lib/celluloid/actor.rb in celluloid-0.9.1 vs lib/celluloid/actor.rb in celluloid-0.10.0
- old
+ new
@@ -21,10 +21,17 @@
class Actor
extend Registry
attr_reader :proxy, :tasks, :links, :mailbox
class << self
+ # Obtain the current actor
+ def current
+ actor = Thread.current[:actor]
+ raise NotActorError, "not in actor scope" unless actor
+ actor.proxy
+ end
+
# Invoke a method on the given actor via its mailbox
def call(mailbox, meth, *args, &block)
call = SyncCall.new(Thread.mailbox, meth, args, block)
begin
@@ -94,15 +101,10 @@
Thread.current[:mailbox] = @mailbox
run
end
end
- # Is this actor alive?
- def alive?
- @running
- end
-
# Is this actor running in exclusive mode?
def exclusive?
@exclusive
end
@@ -115,11 +117,10 @@
end
# Terminate this actor
def terminate
@running = false
- nil
end
# Send a signal with the given name to all waiting methods
def signal(name, value = nil)
@signals.send name, value
@@ -142,9 +143,11 @@
begin
message = @mailbox.receive(timeout)
rescue ExitEvent => exit_event
Task.new(:exit_handler) { handle_exit_event exit_event }.resume
retry
+ rescue TerminationRequest
+ break
end
if message
handle_message message
else