Class: Fibrio::Stream
- Inherits:
-
Object
- Object
- Fibrio::Stream
- Includes:
- Enumerable
- Defined in:
- lib/fibrio/stream.rb
Instance Method Summary collapse
- #close ⇒ void
- #each {|record| ... } ⇒ Enumerator?
-
#initialize(parser) ⇒ Stream
constructor
A new instance of Stream.
Constructor Details
#initialize(parser) ⇒ Stream
Returns a new instance of Stream.
8 9 10 11 12 13 14 15 |
# File 'lib/fibrio/stream.rb', line 8 def initialize(parser) @parser = parser @fiber = Fiber.new do @parser.run { |record| Fiber.yield(record) } nil end @done = false end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
33 34 35 36 |
# File 'lib/fibrio/stream.rb', line 33 def close @done = true @parser.close end |
#each {|record| ... } ⇒ Enumerator?
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fibrio/stream.rb', line 19 def each return enum_for(:each) unless block_given? until @done record = @fiber.resume if record.nil? && !@fiber.alive? @done = true else yield record end end end |