class Async::Condition
@public Since ‘stable-v1`.
A synchronization primitive, which allows fibers to wait until a particular condition is (edge) triggered.
def empty?
Is any fiber waiting on this notification?
def empty? @waiting.empty? end
def initialize
def initialize @waiting = [] end
def signal(value = nil)
Signal to a given task that it should resume operations.
def signal(value = nil) waiting = @waiting @waiting = [] waiting.each do |fiber| Fiber.scheduler.resume(fiber, value) if fiber.alive? end return nil end
def wait
Queue up the current fiber and wait on yielding the task.
def wait queue = Queue.new(Fiber.current) @waiting << queue Fiber.scheduler.transfer ensure queue.nullify end