ConditionVariable-like signaling between tasks and actors
Broadcast a value to all waiting tasks
# File lib/celluloid/condition.rb, line 65 def broadcast(value = nil) @mutex.synchronize do @tasks.each { |waiter| waiter << SignalConditionRequest.new(waiter.task, value) } @tasks.clear end end
Send a signal to the first task waiting on this condition
# File lib/celluloid/condition.rb, line 54 def signal(value = nil) @mutex.synchronize do if waiter = @tasks.shift waiter << SignalConditionRequest.new(waiter.task, value) else Logger.debug("Celluloid::Condition signaled spuriously") end end end
Wait for the given signal and return the associated value
# File lib/celluloid/condition.rb, line 34 def wait raise ConditionError, "cannot wait for signals while exclusive" if Celluloid.exclusive? if Thread.current[:celluloid_actor] task = Task.current else task = Thread.current end waiter = Waiter.new(self, task, Celluloid.mailbox) @mutex.synchronize do @tasks << waiter end result = Celluloid.suspend :condwait, waiter raise result if result.is_a? ConditionError result end
Generated with the Darkfish Rdoc Generator 2.