class Streaming
Wraps a Rack streaming response body.
The body must be callable and accept a stream argument.
When closed, this class ensures the wrapped body's close method is called if it exists.
Definitions
def initialize(body, input = nil)
Initialize the streaming body wrapper.
Signature
-
parameter
bodyObject A callable object that accepts a stream argument, such as a Proc or an object that responds to
call. May optionally respond toclosefor cleanup (e.g.,Rack::BodyProxy).-
parameter
inputProtocol::HTTP::Body::Readable | Nil Optional input body for bi-directional streaming.
Implementation
def initialize(body, input = nil)
@body = body
super
end
def close(error = nil)
Close the streaming body and clean up resources.
If the wrapped body responds to close, it will be called to allow proper cleanup.
This ensures that Rack::BodyProxy cleanup callbacks are invoked correctly.
Signature
-
parameter
errorException | Nil Optional error that caused the stream to close.
Implementation
def close(error = nil)
if body = @body
@body = nil
if body.respond_to?(:close)
body.close
end
end
super
end