Sha256: 3a5bb55c1a65e3304c52a6788013808a61325deebf1965cd2e79e0f6b7ebb790

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

module Celluloid
  # High-priority internal system events
  class SystemEvent; end

  # Request to link with another actor
  class LinkingRequest < SystemEvent
    attr_reader :actor, :type

    def initialize(actor, type)
      @actor, @type = actor, type.to_sym
      raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
    end

    def process(links)
      case type
      when :link   then links << actor
      when :unlink then links.delete actor
      end

      actor.mailbox << LinkingResponse.new(Actor.current, type)
    end
  end

  # Response to a link request
  class LinkingResponse
    attr_reader :actor, :type

    def initialize(actor, type)
      @actor, @type = actor, type.to_sym
      raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
    end
  end

  # An actor has exited for the given reason
  class ExitEvent < SystemEvent
    attr_reader :actor, :reason

    def initialize(actor, reason = nil)
      @actor, @reason = actor, reason
    end
  end

  # Name an actor at the time it's registered
  class NamingRequest < SystemEvent
    attr_reader :name

    def initialize(name)
      @name = name
    end
  end

  # Request for an actor to terminate
  class TerminationRequest < SystemEvent; end

  # Signal a condition
  class SignalConditionRequest < SystemEvent
    def initialize(task, value)
      @task, @value = task, value
    end

    def call
      @task.resume(@value)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/system_events.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/system_events.rb
celluloid-0.14.0 lib/celluloid/system_events.rb
celluloid-0.14.0.pre lib/celluloid/system_events.rb
celluloid-0.13.0 lib/celluloid/system_events.rb
celluloid-0.13.0.pre2 lib/celluloid/system_events.rb
celluloid-0.13.0.pre lib/celluloid/system_events.rb