lib/celluloid/actor_proxy.rb in celluloid-0.0.3 vs lib/celluloid/actor_proxy.rb in celluloid-0.1.0
- old
+ new
@@ -24,15 +24,25 @@
def alive?
@actor.alive?
end
+ def to_s
+ __call :to_s
+ end
+
def inspect
return __call :inspect if alive?
"#<Celluloid::Actor(#{@actor.class}:0x#{@actor.object_id.to_s(16)}) dead>"
end
+ # Terminate the associated actor
+ def terminate
+ raise DeadActorError, "actor already terminated" unless alive?
+ terminate!
+ end
+
# method_missing black magic to call bang predicate methods asynchronously
def method_missing(meth, *args, &block)
# bang methods are async calls
if meth.to_s.match(/!$/)
unbanged_meth = meth.to_s.sub(/!$/, '')
@@ -61,12 +71,18 @@
begin
@mailbox << call
rescue MailboxError
raise DeadActorError, "attempted to call a dead actor"
end
-
- response = our_mailbox.receive do |msg|
- msg.is_a? Response and msg.call == call
+
+ if Celluloid.actor?
+ # Yield to the actor scheduler, which resumes us when we get a response
+ response = Fiber.yield(call)
+ else
+ # Otherwise we're inside a normal thread, so block
+ response = our_mailbox.receive do |msg|
+ msg.is_a? Response and msg.call == call
+ end
end
case response
when SuccessResponse
response.value
\ No newline at end of file