Class: Protocol::HTTP::Body::Streamable::Output
- Inherits:
-
Object
- Object
- Protocol::HTTP::Body::Streamable::Output
- Defined in:
- lib/protocol/http/body/streamable.rb
Overview
A output stream that can be written to by a block.
Class Method Summary collapse
-
.schedule(input, block) ⇒ Object
Schedule the block to be executed in a fiber.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Close the output stream.
-
#initialize(input, block) ⇒ Output
constructor
Initialize the output stream with the given input and block.
-
#read ⇒ Object
Read from the output stream (may block).
-
#schedule ⇒ Object
Schedule the block to be executed in a fiber.
Constructor Details
Class Method Details
.schedule(input, block) ⇒ Object
Schedule the block to be executed in a fiber.
44 45 46 |
# File 'lib/protocol/http/body/streamable.rb', line 44 def self.schedule(input, block) self.new(input, block).tap(&:schedule) end |
Instance Method Details
#close(error = nil) ⇒ Object
Close the output stream.
75 76 77 |
# File 'lib/protocol/http/body/streamable.rb', line 75 def close(error = nil) @output.close_write(error) end |
#read ⇒ Object
Read from the output stream (may block).
68 69 70 |
# File 'lib/protocol/http/body/streamable.rb', line 68 def read @output.read end |
#schedule ⇒ Object
Schedule the block to be executed in a fiber.
61 62 63 64 65 |
# File 'lib/protocol/http/body/streamable.rb', line 61 def schedule @fiber ||= Fiber.schedule do @block.call(@stream) end end |