Class: Celluloid::Signals

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/signals.rb

Overview

Event signaling between methods of the same object

Instance Method Summary collapse

Constructor Details

#initializeSignals

Returns a new instance of Signals.


4
5
6
# File 'lib/celluloid/signals.rb', line 4

def initialize
  @conditions = {}
end

Instance Method Details

#broadcast(name, value = nil) ⇒ Object

Send a signal to all method calls waiting for the given name


17
18
19
20
# File 'lib/celluloid/signals.rb', line 17

def broadcast(name, value = nil)
  condition = @conditions.delete(name)
  condition.broadcast(value) if condition
end

#wait(name) ⇒ Object

Wait for the given signal and return the associated value


9
10
11
12
13
14
# File 'lib/celluloid/signals.rb', line 9

def wait(name)
  raise "cannot wait for signals while exclusive" if Celluloid.exclusive?

  @conditions[name] ||= Condition.new
  @conditions[name].wait
end