Class: Protocol::Rack::Body::Streaming::Output
- Inherits:
-
Object
- Object
- Protocol::Rack::Body::Streaming::Output
- Defined in:
- lib/protocol/rack/body/streaming.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(input, block) ⇒ Output
constructor
A new instance of Output.
- #read ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize(input, block) ⇒ Output
Returns a new instance of Output.
23 24 25 26 27 28 29 |
# File 'lib/protocol/rack/body/streaming.rb', line 23 def initialize(input, block) stream = ::Protocol::HTTP::Body::Stream.new(input, self) @fiber = Fiber.new do block.call(stream) @fiber = nil end end |
Instance Method Details
#close ⇒ Object
35 36 37 |
# File 'lib/protocol/rack/body/streaming.rb', line 35 def close @fiber = nil end |
#read ⇒ Object
39 40 41 |
# File 'lib/protocol/rack/body/streaming.rb', line 39 def read @fiber&.resume end |
#write(chunk) ⇒ Object
31 32 33 |
# File 'lib/protocol/rack/body/streaming.rb', line 31 def write(chunk) Fiber.yield(chunk) end |