Parent

Class/Module Index [+]

Quicksearch

Celluloid::Signals

Event signaling between methods of the same object

Attributes

waiting[R]

Public Class Methods

new() click to toggle source
# File lib/celluloid/signals.rb, line 6
def initialize
  @waiting = {}
end

Public Instance Methods

run_task(task, value) click to toggle source

Run the given task, reporting errors that occur

# File lib/celluloid/signals.rb, line 45
def run_task(task, value)
  task.resume(value)
rescue => ex
  Logger.crash("signaling error", ex)
end
send(name, value = nil) click to toggle source

Send a signal to all method calls waiting for the given name Returns true if any calls were signaled, or false otherwise

# File lib/celluloid/signals.rb, line 29
def send(name, value = nil)
  tasks = @waiting.delete name

  case tasks
  when Array
    tasks.each { |task| run_task task, value }
    true if tasks.size > 0
  when NilClass
    false
  else
    run_task tasks, value
    true
  end
end
wait(signal) click to toggle source

Wait for the given signal and return the associated value

# File lib/celluloid/signals.rb, line 11
def wait(signal)
  raise "cannot wait for signals while exclusive" if Celluloid.exclusive?

  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 :sigwait
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.