Class: Protocol::HTTP::Body::Streamable::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/http/body/streamable.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, block) ⇒ Output

Initialize the output stream with the given input and block.



52
53
54
55
56
# File 'lib/protocol/http/body/streamable.rb', line 52

def initialize(input, block)
	@output = Writable.new
	@stream = Stream.new(input, @output)
	@block = block
end

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

#readObject

Read from the output stream (may block).



68
69
70
# File 'lib/protocol/http/body/streamable.rb', line 68

def read
	@output.read
end

#scheduleObject

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