class Async::Condition

@public Since ‘stable-v1`.
A synchronization primitive, which allows fibers to wait until a particular condition is (edge) triggered.

def empty?

Deprecated:
  • Replaced by {#waiting?}
def empty?
	@waiting.empty?
end

def exchange

def exchange
	waiting = @waiting
	@waiting = List.new
	return waiting
end

def initialize

Create a new condition.
def initialize
	@waiting = List.new
end

def signal(value = nil)

@parameter value [Object | Nil] The value to return to the waiting fibers.
Signal to a given task that it should resume operations.
def signal(value = nil)
	return if @waiting.empty?
	
	waiting = self.exchange
	
	waiting.each do |fiber|
		Fiber.scheduler.resume(fiber, value) if fiber.alive?
	end
	
	return nil
end

def wait

@returns [Object]
Queue up the current fiber and wait on yielding the task.
def wait
	@waiting.stack(FiberNode.new(Fiber.current)) do
		Fiber.scheduler.transfer
	end
end

def waiting?

@returns [Boolean] Is any fiber waiting on this notification?
def waiting?
	@waiting.size > 0
end