Sha256: 432a43951c6bdcce8e70ed4b4f1cde507842868ad28ceefdafd6377d8f3f593e

Contents?: true

Size: 1.1 KB

Versions: 69

Compression:

Stored size: 1.1 KB

Contents

module Celluloid
  # Event signaling between methods of the same object
  class Signals
    attr_reader :waiting

    def initialize
      @waiting = {}
    end

    # Wait for the given signal and return the associated value
    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

    # Send a signal to all method calls waiting for the given name
    # Returns true if any calls were signaled, or false otherwise
    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

    # Run the given task, reporting errors that occur
    def run_task(task, value)
      task.resume(value)
    rescue => ex
      Celluloid::Logger.crash("signaling error", ex)
    end
  end
end

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
engineyard-serverside-2.0.4 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.5 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.3 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.2 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.1 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.rc1 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.pre5 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.pre4 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.pre3 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.pre2 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-2.0.0.pre1 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.7.0.pre2 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre6 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre5 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre4 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre3 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre2 lib/vendor/celluloid/lib/celluloid/signals.rb
engineyard-serverside-1.6.4.pre lib/vendor/celluloid/lib/celluloid/signals.rb