Class: Celluloid::ActorProxy
- Defined in:
- lib/vendor/celluloid/lib/celluloid/actor_proxy.rb
Overview
A proxy object returned from Celluloid::Actor.spawn/spawn_link which dispatches calls and casts to normal Ruby objects which are running inside of their own threads.
Instance Attribute Summary collapse
-
#mailbox ⇒ Object
readonly
Returns the value of attribute mailbox.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #class ⇒ Object
-
#future(method_name, *args, &block) ⇒ Object
Create a Celluloid::Future which calls a given method.
-
#initialize(mailbox, klass = "Object") ⇒ ActorProxy
constructor
A new instance of ActorProxy.
- #inspect ⇒ Object
-
#method_missing(meth, *args, &block) ⇒ Object
method_missing black magic to call bang predicate methods asynchronously.
- #methods(include_ancestors = true) ⇒ Object
- #respond_to?(meth) ⇒ Boolean
- #send(meth, *args, &block) ⇒ Object
-
#terminate ⇒ Object
Terminate the associated actor.
- #to_s ⇒ Object
Constructor Details
#initialize(mailbox, klass = "Object") ⇒ ActorProxy
Returns a new instance of ActorProxy.
8 9 10 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 8 def initialize(mailbox, klass = "Object") @mailbox, @klass = mailbox, klass end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
method_missing black magic to call bang predicate methods asynchronously
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 64 def method_missing(meth, *args, &block) # bang methods are async calls if meth.to_s.match(/!$/) unbanged_meth = meth.to_s.sub(/!$/, '') Actor.async @mailbox, unbanged_meth, *args, &block return end Actor.call @mailbox, meth, *args, &block end |
Instance Attribute Details
#mailbox ⇒ Object (readonly)
Returns the value of attribute mailbox.
6 7 8 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 6 def mailbox @mailbox end |
Instance Method Details
#alive? ⇒ Boolean
28 29 30 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 28 def alive? @mailbox.alive? end |
#class ⇒ Object
16 17 18 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 16 def class Actor.call @mailbox, :send, :class end |
#future(method_name, *args, &block) ⇒ Object
Create a Celluloid::Future which calls a given method
43 44 45 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 43 def future(method_name, *args, &block) Future.new { Actor.call @mailbox, method_name, *args, &block } end |
#inspect ⇒ Object
36 37 38 39 40 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 36 def inspect Actor.call @mailbox, :inspect rescue DeadActorError "#<Celluloid::Actor(#{@klass}) dead>" end |
#methods(include_ancestors = true) ⇒ Object
24 25 26 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 24 def methods(include_ancestors = true) Actor.call @mailbox, :methods, include_ancestors end |
#respond_to?(meth) ⇒ Boolean
20 21 22 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 20 def respond_to?(meth) Actor.call @mailbox, :respond_to?, meth end |
#send(meth, *args, &block) ⇒ Object
12 13 14 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 12 def send(meth, *args, &block) Actor.call @mailbox, :send, meth, *args, &block end |
#terminate ⇒ Object
Terminate the associated actor
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vendor/celluloid/lib/celluloid/actor_proxy.rb', line 48 def terminate raise DeadActorError, "actor already terminated" unless alive? begin send :terminate rescue DeadActorError # In certain cases this is thrown during termination. This is likely # a bug in Celluloid's internals, but it shouldn't affect the caller. # FIXME: track this down and fix it, or at the very least log it end # Always return nil until a dependable exit value can be obtained nil end |