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 resume(value = nil, task: Task.current)

Returns:
  • (void) -
def resume(value = nil, task: Task.current)
	return if @waiting.empty?
	
	task.reactor << Signal.new(@waiting, value)
	
	@waiting = []
	
	return nil
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
	@waiting << Fiber.current
	
	Task.yield
end