Class: SimpleActor
- Inherits:
-
Object
- Object
- SimpleActor
- Defined in:
- lib/ara/simple_actor.rb
Overview
This class allow you to create simple actors.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ SimpleActor
constructor
:nodoc:.
-
#start ⇒ Object
Start actor and return it.
-
#stop ⇒ Object
Stop actor.
-
#|(message) ⇒ Object
(also: #message)
Send a simple message without expecting any response.
Constructor Details
#initialize ⇒ SimpleActor
:nodoc:
5 6 7 8 |
# File 'lib/ara/simple_actor.rb', line 5 def initialize #:nodoc: raise ActorInitializationError, "You can't initialize SimpleActor directly, use Actors.actor_of" if self.class == ::SimpleActor @actorQueue = Queue.new end |
Instance Method Details
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ara/simple_actor.rb', line 14 def start self.send(:pre_start) if self.respond_to?(:pre_start, true) @thread = Thread.new do loop do receive(@actorQueue.shift) end end return self end |
#stop ⇒ Object
30 31 32 33 |
# File 'lib/ara/simple_actor.rb', line 30 def stop @thread.kill self.send(:post_stop) if self.respond_to?(:post_stop, true) end |
#|(message) ⇒ Object Also known as: message
40 41 42 43 44 45 46 |
# File 'lib/ara/simple_actor.rb', line 40 def |() if @thread.alive? @actorQueue << else raise DeadActor, "Actor is dead!" end end |