Class: Celluloid::Call::Sync
Overview
Synchronous calls wait for a response
Instance Attribute Summary collapse
#arguments, #block, #method
Instance Method Summary
collapse
#check, #execute_block_on_receiver
Constructor Details
#initialize(sender, method, arguments = [], block = nil, task = , chain_id = Internals::CallChain.current_id) ⇒ Sync
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/celluloid/call/sync.rb', line 7
def initialize(
sender,
method,
arguments = [],
block = nil,
task = Thread.current[:celluloid_task],
chain_id = Internals::CallChain.current_id
)
super(method, arguments, block)
@sender = sender
@task = task
@chain_id = chain_id || Celluloid.uuid
end
|
Instance Attribute Details
#chain_id ⇒ Object
Returns the value of attribute chain_id.
5
6
7
|
# File 'lib/celluloid/call/sync.rb', line 5
def chain_id
@chain_id
end
|
#sender ⇒ Object
Returns the value of attribute sender.
5
6
7
|
# File 'lib/celluloid/call/sync.rb', line 5
def sender
@sender
end
|
#task ⇒ Object
Returns the value of attribute task.
5
6
7
|
# File 'lib/celluloid/call/sync.rb', line 5
def task
@task
end
|
Instance Method Details
#cleanup ⇒ Object
38
39
40
41
|
# File 'lib/celluloid/call/sync.rb', line 38
def cleanup
exception = DeadActorError.new("attempted to call a dead actor: #{method}")
respond Internals::Response::Error.new(self, exception)
end
|
#dispatch(obj) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/celluloid/call/sync.rb', line 21
def dispatch(obj)
Internals::CallChain.current_id = @chain_id
result = super(obj)
respond Internals::Response::Success.new(self, result)
rescue ::Exception => ex
respond Internals::Response::Error.new(self, ex)
raise unless ex.is_a?(AbortError)
ensure
Internals::CallChain.current_id = nil
end
|
#respond(message) ⇒ Object
43
44
45
|
# File 'lib/celluloid/call/sync.rb', line 43
def respond(message)
@sender << message
end
|
#response ⇒ Object
47
48
49
|
# File 'lib/celluloid/call/sync.rb', line 47
def response
Celluloid.suspend(:callwait, self)
end
|
#value ⇒ Object
51
52
53
|
# File 'lib/celluloid/call/sync.rb', line 51
def value
response.value
end
|
#wait ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/celluloid/call/sync.rb', line 55
def wait
loop do
message = Celluloid.mailbox.receive do |msg|
msg.respond_to?(:call) && msg.call == self
end
if message.is_a?(SystemEvent)
Thread.current[:celluloid_actor].handle_system_event(message)
else
if message.respond_to?(:value)
return message
else
message.dispatch
end
end
end
end
|