Class: Concurrent::Actor::Behaviour::Pausing
- Defined in:
- lib-edge/concurrent/actor/behaviour/pausing.rb
Overview
Note:
TODO missing example
Allows to pause actors on errors. When paused all arriving messages are collected and processed after the actor is resumed or reset. Resume will simply continue with next message. Reset also reinitialized context.
Instance Method Summary collapse
-
#initialize(core, subsequent, core_options) ⇒ Pausing
constructor
A new instance of Pausing.
- #on_envelope(envelope) ⇒ undocumented
- #on_event(public, event) ⇒ undocumented
- #pause!(error = nil) ⇒ undocumented
- #paused? ⇒ Boolean
- #reset! ⇒ undocumented
- #restart! ⇒ undocumented
- #resume! ⇒ undocumented
Constructor Details
#initialize(core, subsequent, core_options) ⇒ Pausing
Returns a new instance of Pausing
11 12 13 14 15 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 11 def initialize(core, subsequent, ) super core, subsequent, @paused = false @deferred = [] end |
Instance Method Details
#on_envelope(envelope) ⇒ undocumented
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 21 def on_envelope(envelope) case envelope. when :pause! pause! when :paused? paused? when :resume! resume! when :reset! reset! when :restart! restart! else if paused? @deferred << envelope MESSAGE_PROCESSED else pass envelope end end end |
#on_event(public, event) ⇒ undocumented
72 73 74 75 76 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 72 def on_event(public, event) event_name, _ = event reject_deferred if event_name == :terminated super public, event end |
#pause!(error = nil) ⇒ undocumented
43 44 45 46 47 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 43 def pause!(error = nil) do_pause broadcast true, error || :paused true end |
#paused? ⇒ Boolean
17 18 19 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 17 def paused? @paused end |
#reset! ⇒ undocumented
56 57 58 59 60 61 62 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 56 def reset! return false unless paused? broadcast(false, :resetting) do_reset broadcast(true, :reset) true end |
#restart! ⇒ undocumented
64 65 66 67 68 69 70 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 64 def restart! return false unless paused? broadcast(false, :restarting) do_restart broadcast(true, :restarted) true end |
#resume! ⇒ undocumented
49 50 51 52 53 54 |
# File 'lib-edge/concurrent/actor/behaviour/pausing.rb', line 49 def resume! return false unless paused? do_resume broadcast(true, :resumed) true end |