Class: Celluloid::Signals
- Defined in:
- lib/vendor/celluloid/lib/celluloid/signals.rb
Overview
Event signaling between methods of the same object
Instance Attribute Summary collapse
-
#waiting ⇒ Object
readonly
Returns the value of attribute waiting.
Instance Method Summary collapse
-
#initialize ⇒ Signals
constructor
A new instance of Signals.
-
#run_task(task, value) ⇒ Object
Run the given task, reporting errors that occur.
-
#send(name, value = nil) ⇒ Object
Send a signal to all method calls waiting for the given name Returns true if any calls were signaled, or false otherwise.
-
#wait(signal) ⇒ Object
Wait for the given signal and return the associated value.
Constructor Details
#initialize ⇒ Signals
Returns a new instance of Signals.
6 7 8 |
# File 'lib/vendor/celluloid/lib/celluloid/signals.rb', line 6 def initialize @waiting = {} end |
Instance Attribute Details
#waiting ⇒ Object (readonly)
Returns the value of attribute waiting.
4 5 6 |
# File 'lib/vendor/celluloid/lib/celluloid/signals.rb', line 4 def waiting @waiting end |
Instance Method Details
#run_task(task, value) ⇒ Object
Run the given task, reporting errors that occur
44 45 46 47 48 |
# File 'lib/vendor/celluloid/lib/celluloid/signals.rb', line 44 def run_task(task, value) task.resume(value) rescue => ex Celluloid::Logger.crash("signaling error", ex) end |
#send(name, value = nil) ⇒ Object
Send a signal to all method calls waiting for the given name Returns true if any calls were signaled, or false otherwise
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/celluloid/lib/celluloid/signals.rb', line 28 def send(name, value = nil) tasks = @waiting.delete name case tasks when Array tasks.each { |task| run_task task, value } when NilClass Logger.debug("spurious signal: #{name}") else run_task tasks, value end value end |
#wait(signal) ⇒ Object
Wait for the given signal and return the associated value
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vendor/celluloid/lib/celluloid/signals.rb', line 11 def wait(signal) tasks = @waiting[signal] case tasks when Array tasks << Task.current when NilClass @waiting[signal] = Task.current else @waiting[signal] = [tasks, Task.current] end Task.suspend end |