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.



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

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

Instance Method Details

#awaitObject

Raises:

  • (StopIteration)


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

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: <<



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

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