Class: Celluloid::SyncCall

Inherits:
Call
  • Object
show all
Defined in:
lib/celluloid/calls.rb

Overview

Synchronous calls wait for a response

Instance Attribute Summary collapse

Attributes inherited from Call

#arguments, #block, #caller, #method

Instance Method Summary collapse

Methods inherited from Call

#check_signature

Constructor Details

#initialize(caller, method, arguments = [], block = nil, task = Fiber.current.task) ⇒ SyncCall

Returns a new instance of SyncCall.



42
43
44
45
# File 'lib/celluloid/calls.rb', line 42

def initialize(caller, method, arguments = [], block = nil, task = Fiber.current.task)
  super(caller, method, arguments, block)
  @task = task
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task.



40
41
42
# File 'lib/celluloid/calls.rb', line 40

def task
  @task
end

Instance Method Details

#cleanupObject



75
76
77
78
# File 'lib/celluloid/calls.rb', line 75

def cleanup
  exception = DeadActorError.new("attempted to call a dead actor")
  respond ErrorResponse.new(self, exception)
end

#dispatch(obj) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/celluloid/calls.rb', line 47

def dispatch(obj)
  begin
    check_signature(obj)
  rescue => ex
    respond ErrorResponse.new(self, AbortError.new(ex))
    return
  end

  begin
    result = obj.send @method, *@arguments, &@block
  rescue Exception => exception
    # Exceptions that occur during synchronous calls are reraised in the
    # context of the caller
    respond ErrorResponse.new(self, exception)

    if exception.is_a? AbortError
      # Aborting indicates a protocol error on the part of the caller
      # It should crash the caller, but the exception isn't reraised
      return
    else
      # Otherwise, it's a bug in this actor and should be reraised
      raise exception
    end
  end

  respond SuccessResponse.new(self, result)
end

#respond(message) ⇒ Object



80
81
82
83
84
85
# File 'lib/celluloid/calls.rb', line 80

def respond(message)
  @caller << message
rescue MailboxError
  # It's possible the caller exited or crashed before we could send a
  # response to them.
end