class Protocol::HTTP::Body::Streamable::Output

A output stream that can be written to by a block.

def self.schedule(input, block)

@returns [Output] The output stream.
@parameter block [Proc] The block that generates the output.
@parameter input [Readable] The input stream.

Schedule the block to be executed in a fiber.
def self.schedule(input, block)
	self.new(input, block).tap(&:schedule)
end

def close(error = nil)

@parameter error [Exception | Nil] The error that caused this stream to be closed, if any.

Close the output stream.
def close(error = nil)
	@output.close_write(error)
end

def initialize(input, block)

@parameter block [Proc] The block that generates the output.
@parameter input [Readable] The input stream.

Initialize the output stream with the given input and block.
def initialize(input, block)
	@output = Writable.new
	@stream = Stream.new(input, @output)
	@block = block
end

def read

Read from the output stream (may block).
def read
	@output.read
end

def schedule

@returns [Fiber] The fiber.

Schedule the block to be executed in a fiber.
def schedule
	@fiber ||= Fiber.schedule do
		@block.call(@stream)
	end
end