Class: Falcon::Body::RequestFinished
- Inherits:
-
Protocol::HTTP::Body::Wrapper
- Object
- Protocol::HTTP::Body::Wrapper
- Falcon::Body::RequestFinished
- Defined in:
- lib/falcon/body/request_finished.rb
Overview
Wraps a response body and decrements a metric after the body is closed.
Runs close on the underlying body first (which invokes rack.response_finished), then decrements the metric. Use this so requests_active stays elevated until the request is fully finished (including response_finished callbacks).
Class Method Summary collapse
-
.wrap(message, metric) ⇒ Object
Wrap a response body with a metric.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Closes the underlying body (invoking rack.response_finished), then decrements the metric.
-
#initialize(body, metric) ⇒ RequestFinished
constructor
A new instance of RequestFinished.
- #rewind ⇒ Object
- #rewindable? ⇒ Boolean
Constructor Details
#initialize(body, metric) ⇒ RequestFinished
Returns a new instance of RequestFinished.
34 35 36 37 38 |
# File 'lib/falcon/body/request_finished.rb', line 34 def initialize(body, metric) super(body) @metric = metric end |
Class Method Details
.wrap(message, metric) ⇒ Object
Wrap a response body with a metric. If the body is nil or empty, decrements immediately.
22 23 24 25 26 27 28 29 30 |
# File 'lib/falcon/body/request_finished.rb', line 22 def self.wrap(, metric) if body = &.body and !body.empty? .body = new(body, metric) else metric.decrement end end |
Instance Method Details
#close(error = nil) ⇒ Object
Closes the underlying body (invoking rack.response_finished), then decrements the metric.
53 54 55 56 57 58 |
# File 'lib/falcon/body/request_finished.rb', line 53 def close(error = nil) super @metric&.decrement @metric = nil end |
#rewind ⇒ Object
46 47 48 |
# File 'lib/falcon/body/request_finished.rb', line 46 def rewind false end |
#rewindable? ⇒ Boolean
41 42 43 |
# File 'lib/falcon/body/request_finished.rb', line 41 def rewindable? false end |