Module: Actor::Module
- Defined in:
- lib/actor/actor.rb
Defined Under Namespace
Modules: Start
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #configure ⇒ Object
- #continuations ⇒ Object
- #handle(message) ⇒ Object
- #handle?(message) ⇒ Boolean
- #handle_stop ⇒ Object
- #next ⇒ Object
- #run_loop ⇒ Object (also: #start)
Instance Attribute Details
#address ⇒ Object
85 86 87 |
# File 'lib/actor/actor.rb', line 85 def address @address ||= Address::None end |
#reader ⇒ Object
89 90 91 |
# File 'lib/actor/actor.rb', line 89 def reader @reader ||= Messaging::Read::Substitute.new end |
#writer ⇒ Object
93 94 95 |
# File 'lib/actor/actor.rb', line 93 def writer @writer ||= Messaging::Write::Substitute.new end |
Class Method Details
.included(cls) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/actor/actor.rb', line 13 def self.included cls cls.class_exec do extend Build extend HandleMacro extend Start include Observers end end |
Instance Method Details
#configure ⇒ Object
27 28 |
# File 'lib/actor/actor.rb', line 27 def configure end |
#continuations ⇒ Object
30 31 32 |
# File 'lib/actor/actor.rb', line 30 def continuations @continuations ||= [] end |
#handle(message) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/actor/actor.rb', line 34 def handle method = handle? return if method.nil? if method.arity == 0 return_value = method.() else return_value = method.() end notify_observers return_value end |
#handle?(message) ⇒ Boolean
54 55 56 57 58 59 60 |
# File 'lib/actor/actor.rb', line 54 def handle? method_name = HandleMacro::MethodName.get if respond_to? method_name method method_name end end |
#handle_stop ⇒ Object
50 51 52 |
# File 'lib/actor/actor.rb', line 50 def handle_stop raise StopIteration end |
#next ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/actor/actor.rb', line 62 def next if continuations.empty? = reader.(wait: true) else = reader.(wait: false) ||= continuations.shift end = handle if handle? continuations << end end |
#run_loop ⇒ Object Also known as: start
77 78 79 80 81 82 |
# File 'lib/actor/actor.rb', line 77 def run_loop loop do self.next Thread.pass end end |