class Pupa::Processor::Yielder
A lazy enumerator.
Public Class Methods
new() { || ... }
click to toggle source
The given block should yield objects to add to the enumerator.
# File lib/pupa/processor/yielder.rb, line 10 def initialize @fiber = Fiber.new do yield raise StopIteration end end
Public Instance Methods
each() { |next| ... }
click to toggle source
Yields each object in the enumerator to the given block.
# File lib/pupa/processor/yielder.rb, line 18 def each if block_given? loop do yield self.next end else to_enum end end
next()
click to toggle source
Returns the next object in the enumerator, and moves the internal position forward. When the position reaches the end, ‘StopIteration` is raised.
# File lib/pupa/processor/yielder.rb, line 30 def next if @fiber.alive? @fiber.resume else raise StopIteration end end
to_enum()
click to toggle source
Returns a lazy enumerator.
@return [Enumerator] a lazy enumerator
# File lib/pupa/processor/yielder.rb, line 41 def to_enum Enumerator.new do |y| loop do y << self.next end end end