Class: Actor
- Inherits:
-
SimpleActor
- Object
- SimpleActor
- Actor
- Defined in:
- lib/ara/actor.rb
Overview
Actor class
Instance Method Summary collapse
-
#<(message, response_method = nil) ⇒ Object
(also: #async_message)
Send an asynchronous message.
-
#<<(message) ⇒ Object
(also: #sync_message)
Send a synchronous message.
-
#initialize ⇒ Actor
constructor
:nodoc:.
Methods inherited from SimpleActor
Constructor Details
#initialize ⇒ Actor
:nodoc:
6 7 8 9 10 |
# File 'lib/ara/actor.rb', line 6 def initialize #:nodoc: raise ActorInitializationError, "You can't initialize Actor directly, use Actors.actor_of" if self.class == ::Actor super @main = Queue.new end |
Instance Method Details
#<(message, response_method = nil) ⇒ Object Also known as: async_message
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ara/actor.rb', line 36 def <(, response_method = nil) if @thread.alive? @actorQueue << BindingOfCaller.binding_of_caller do |bind| self_of_caller = eval("self", bind) Thread.new do _result = @main.pop begin if block_given? yield _result elsif response_method != nil self_of_caller.send( response_method.to_sym, _result ) else self_of_caller.send( :actor_response, _result ) end rescue => e raise ActorResponseError, "Error while sending response : #{e}" end end end else raise DeadActor, "Actor is dead!" end end |
#<<(message) ⇒ Object Also known as: sync_message
19 20 21 22 23 24 25 26 |
# File 'lib/ara/actor.rb', line 19 def <<() if @thread.alive? @actorQueue << @main.pop else raise DeadActor, "Actor is dead!" end end |