Class: Celluloid::Internals::Signals

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

Overview

Event signaling between methods of the same object

Instance Method Summary collapse

Constructor Details

#initializeSignals

Returns a new instance of Signals.


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

def initialize
  @conditions = {}
end

Instance Method Details

#broadcast(name, value = nil) ⇒ Object

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


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

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


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

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

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