Module: Celluloid::ClassMethods
- Defined in:
- lib/vendor/celluloid/lib/celluloid.rb
Overview
Class methods added to classes which include Celluloid
Instance Attribute Summary collapse
-
#exit_handler ⇒ Object
readonly
Obtain the exit handler for this actor.
Instance Method Summary collapse
-
#new(*args, &block) ⇒ Object
(also: #spawn)
Create a new actor.
-
#new_link(*args, &block) ⇒ Object
(also: #spawn_link)
Create a new actor and link to the current one.
-
#supervise(*args, &block) ⇒ Object
Create a supervisor which ensures an instance of an actor will restart an actor if it fails.
-
#supervise_as(name, *args, &block) ⇒ Object
Create a supervisor which ensures an instance of an actor will restart an actor if it fails, and keep the actor registered under a given name.
-
#trap_exit(callback) ⇒ Object
Trap errors from actors we’re linked to when they exit.
-
#use_mailbox(klass = nil, &block) ⇒ Object
Configure a custom mailbox factory.
Instance Attribute Details
#exit_handler ⇒ Object (readonly)
Obtain the exit handler for this actor
95 96 97 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 95 def exit_handler @exit_handler end |
Instance Method Details
#new(*args, &block) ⇒ Object Also known as: spawn
Create a new actor
58 59 60 61 62 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 58 def new(*args, &block) proxy = Actor.new(allocate).proxy proxy.send(:initialize, *args, &block) proxy end |
#new_link(*args, &block) ⇒ Object Also known as: spawn_link
Create a new actor and link to the current one
66 67 68 69 70 71 72 73 74 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 66 def new_link(*args, &block) current_actor = Celluloid.current_actor raise NotActorError, "can't link outside actor context" unless current_actor proxy = Actor.new(allocate).proxy current_actor.link proxy proxy.send(:initialize, *args, &block) proxy end |
#supervise(*args, &block) ⇒ Object
Create a supervisor which ensures an instance of an actor will restart an actor if it fails
79 80 81 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 79 def supervise(*args, &block) Supervisor.supervise(self, *args, &block) end |
#supervise_as(name, *args, &block) ⇒ Object
Create a supervisor which ensures an instance of an actor will restart an actor if it fails, and keep the actor registered under a given name
85 86 87 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 85 def supervise_as(name, *args, &block) Supervisor.supervise_as(name, self, *args, &block) end |
#trap_exit(callback) ⇒ Object
Trap errors from actors we’re linked to when they exit
90 91 92 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 90 def trap_exit(callback) @exit_handler = callback.to_sym end |
#use_mailbox(klass = nil, &block) ⇒ Object
Configure a custom mailbox factory
98 99 100 101 102 103 104 |
# File 'lib/vendor/celluloid/lib/celluloid.rb', line 98 def use_mailbox(klass = nil, &block) if block define_method(:mailbox_factory, &block) else define_method(:mailbox_factory) { klass.new } end end |