Class: Transformer::SecondYielder

Inherits:
Consumer::Yielder show all
Defined in:
lib/coroutines/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(y, fiber) ⇒ SecondYielder

Returns a new instance of SecondYielder.



567
568
569
# File 'lib/coroutines/base.rb', line 567

def initialize(y, fiber)
  @y, @fiber = y, fiber
end

Instance Method Details

#awaitObject

Raises:

  • (StopIteration)


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/coroutines/base.rb', line 572

def await
  raise StopIteration unless @fiber.alive?
  tag, result = @fiber.resume
  while tag == :await do
    x = nil
    begin
      x = @y.await
    rescue Exception => e
      tag, result = @fiber.raise(e)
    end
    tag, result = @fiber.resume(*x) unless x.nil?
    raise StopIteration unless @fiber.alive?
  end
  result
end

#yield(*args) ⇒ Object Also known as: <<



604
605
606
607
# File 'lib/coroutines/base.rb', line 604

def yield(*args)
  @y.yield(*args)
  self
end