class Async::Condition

A synchronization primative, which allows fibers to wait until a particular condition is triggered. Signalling the condition directly resumes the waiting fibers and thus blocks the caller.

def empty?

Returns:
  • (Boolean) -
def empty?
	@waiting.empty?
end

def initialize

def initialize
	@waiting = []
end

def signal(value = nil)

Returns:
  • (void) -

Other tags:
    See: Task.yield - which is responsible for handling value.

Parameters:
  • value () -- The value to return to the waiting fibers.
def signal(value = nil)
	waiting = @waiting
	@waiting = []
	
	waiting.each do |fiber|
		fiber.resume(value) if fiber.alive?
	end
	
	return nil
end

def wait

Returns:
  • (Object) -
def wait
	fiber = Fiber.current
	
	@waiting << fiber
	Task.yield
	
	# It would be nice if there was a better construct for this. We only need to invoke #delete if the task was not resumed normally. This can only occur with `raise` and `throw`. But there is no easy way to detect this.
# ensure when not return or ensure when raise, throw
rescue Exception
	@waiting.delete(fiber)
	raise
end