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:
6 7 8 9 |
# File 'lib/ara/simple_actor.rb', line 6 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
15 16 17 18 19 20 21 22 23 |
# File 'lib/ara/simple_actor.rb', line 15 def start @thread = Thread.new do loop do receive(@actorQueue.pop) end end return self end |
#stop ⇒ Object
30 31 32 |
# File 'lib/ara/simple_actor.rb', line 30 def stop @thread.kill end |
#|(message) ⇒ Object Also known as: message
39 40 41 42 43 44 45 |
# File 'lib/ara/simple_actor.rb', line 39 def |() if @thread.alive? @actorQueue << else raise DeadActor, "Actor is dead!" end end |