Class: LongBody::ThinHandler::FiberWrapper
- Inherits:
-
Object
- Object
- LongBody::ThinHandler::FiberWrapper
- Defined in:
- lib/long_body/thin_handler.rb
Overview
A wrapper that allows us to access an object that yields from each() as if it were an Enumerator-ish object.
arr = %w( a b )
w = FiberWrapper.new(arr)
w.take #=> 'a'
w.take #=> 'b'
w.take #=> nil # Ended
Instance Method Summary collapse
-
#initialize(eachable) ⇒ FiberWrapper
constructor
A new instance of FiberWrapper.
- #take ⇒ Object
Constructor Details
#initialize(eachable) ⇒ FiberWrapper
Returns a new instance of FiberWrapper.
18 19 20 21 22 23 24 |
# File 'lib/long_body/thin_handler.rb', line 18 def initialize(eachable) @fiber = Fiber.new do eachable.each{|chunk| Fiber.yield(chunk.to_s) } eachable.close if eachable.respond_to?(:close) nil end end |
Instance Method Details
#take ⇒ Object
26 27 28 29 30 |
# File 'lib/long_body/thin_handler.rb', line 26 def take @fiber.resume rescue FiberError nil end |