Class: Protocol::Rack::Body::Streaming::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/rack/body/streaming.rb

Instance Method Summary collapse

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

#closeObject



35
36
37
# File 'lib/protocol/rack/body/streaming.rb', line 35

def close
	@fiber = nil
end

#readObject



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