Class/Module Index [+]

Quicksearch

Celluloid::SyncCall

Synchronous calls wait for a response

Attributes

chain_id[R]
sender[R]
task[R]

Public Class Methods

new(sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = Thread.current[:celluloid_chain_id]) click to toggle source
# File lib/celluloid/calls.rb, line 57
def initialize(sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = Thread.current[:celluloid_chain_id])
  super(method, arguments, block)

  @sender   = sender
  @task     = task
  @chain_id = chain_id || Celluloid.uuid
end

Public Instance Methods

cleanup() click to toggle source
# File lib/celluloid/calls.rb, line 82
def cleanup
  exception = DeadActorError.new("attempted to call a dead actor")
  respond ErrorResponse.new(self, exception)
end
dispatch(obj) click to toggle source
# File lib/celluloid/calls.rb, line 65
def dispatch(obj)
  Thread.current[:celluloid_chain_id] = @chain_id
  result = super(obj)
  respond SuccessResponse.new(self, result)
rescue Exception => ex
  # Exceptions that occur during synchronous calls are reraised in the
  # context of the sender
  respond ErrorResponse.new(self, ex)

  # Aborting indicates a protocol error on the part of the sender
  # It should crash the sender, but the exception isn't reraised
  # Otherwise, it's a bug in this actor and should be reraised
  raise unless ex.is_a?(AbortError)
ensure
  Thread.current[:celluloid_chain_id] = nil
end
respond(message) click to toggle source
# File lib/celluloid/calls.rb, line 87
def respond(message)
  @sender << message
rescue MailboxError
  # It's possible the sender exited or crashed before we could send a
  # response to them.
end
value() click to toggle source
# File lib/celluloid/calls.rb, line 94
def value
  Celluloid.suspend(:callwait, self).value
end
wait() click to toggle source
# File lib/celluloid/calls.rb, line 98
def wait
  loop do
    message = Celluloid.mailbox.receive do |msg|
      msg.respond_to?(:call) and msg.call == self
    end

    if message.is_a?(SystemEvent)
      Thread.current[:celluloid_actor].handle_system_event(message)
    else
      # FIXME: add check for receiver block execution
      if message.respond_to?(:value)
        # FIXME: disable block execution if on :sender and (exclusive or outside of task)
        # probably now in Call
        break message
      else
        message.dispatch
      end
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.