Class: Concurrent::Actor::Behaviour::Linking
- Defined in:
- lib/concurrent/actor/behaviour/linking.rb
Overview
Links the actor to other actors and sends actor’s events to them, like: ‘:terminated`, `:paused`, errors, etc TODO example
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(core, subsequent) ⇒ Linking
constructor
A new instance of Linking.
- #link(ref) ⇒ Object
- #on_envelope(envelope) ⇒ Object
- #on_event(event) ⇒ Object
- #unlink(ref) ⇒ Object
Methods inherited from Abstract
#broadcast, #pass, #reject_envelope
Methods included from InternalDelegations
#behaviour, #behaviour!, #children, #context, #dead_letter_routing, #log, #redirect, #terminate!
Methods included from PublicDelegations
#context_class, #executor, #name, #parent, #path, #reference
Methods included from TypeCheck
#Child!, #Child?, #Match!, #Match?, #Type!, #Type?
Constructor Details
#initialize(core, subsequent) ⇒ Linking
Returns a new instance of Linking.
9 10 11 12 |
# File 'lib/concurrent/actor/behaviour/linking.rb', line 9 def initialize(core, subsequent) super core, subsequent @linked = Set.new end |
Instance Method Details
#link(ref) ⇒ Object
27 28 29 30 |
# File 'lib/concurrent/actor/behaviour/linking.rb', line 27 def link(ref) @linked.add(ref) true end |
#on_envelope(envelope) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/concurrent/actor/behaviour/linking.rb', line 14 def on_envelope(envelope) case envelope. when :link link envelope.sender when :unlink unlink envelope.sender when :linked? @linked.include? envelope.sender else pass envelope end end |
#on_event(event) ⇒ Object
37 38 39 40 41 |
# File 'lib/concurrent/actor/behaviour/linking.rb', line 37 def on_event(event) @linked.each { |a| a << event } @linked.clear if event == :terminated super event end |
#unlink(ref) ⇒ Object
32 33 34 35 |
# File 'lib/concurrent/actor/behaviour/linking.rb', line 32 def unlink(ref) @linked.delete(ref) true end |