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
|
# 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
31
32
33
34
|
# File 'lib/celluloid/call/sync.rb', line 31
def cleanup
exception = DeadActorError.new("attempted to call a dead actor")
respond Internals::Response::Error.new(self, exception)
end
|
#dispatch(obj) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/celluloid/call/sync.rb', line 14
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
36
37
38
|
# File 'lib/celluloid/call/sync.rb', line 36
def respond(message)
@sender << message
end
|
#response ⇒ Object
40
41
42
|
# File 'lib/celluloid/call/sync.rb', line 40
def response
Celluloid.suspend(:callwait, self)
end
|
#value ⇒ Object
44
45
46
|
# File 'lib/celluloid/call/sync.rb', line 44
def value
response.value
end
|
#wait ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/celluloid/call/sync.rb', line 48
def wait
while true
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
|