Class: Genesis::Reactor
- Inherits:
-
Object
- Object
- Genesis::Reactor
- Defined in:
- lib/genesis/reactor.rb
Overview
Main reactor class rubocop:disable ClassLength
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Reactor
constructor
A new instance of Reactor.
-
#run ⇒ Object
Run the reactor - must be called from EM.run or EM.synchrony.
-
#running? ⇒ Boolean
Check if the reactor is running.
-
#start ⇒ Object
Convenience wrapper to run indefinitely as daemon.
-
#stop ⇒ Object
Stop the reactor.
Constructor Details
#initialize(**kwargs) ⇒ Reactor
Returns a new instance of Reactor.
18 19 20 21 22 23 24 25 26 |
# File 'lib/genesis/reactor.rb', line 18 def initialize(**kwargs) reset @poolsize = kwargs[:threads] || 100 # maximum concurrency - larger = longer boot and shutdown time @protocols = kwargs[:protocols] || {} @views = kwargs[:views] || {} @debug = kwargs[:debug] || false register_handlers(kwargs[:handlers] || {}) register_agents(kwargs[:agents] || []) end |
Instance Method Details
#run ⇒ Object
Run the reactor - must be called from EM.run or EM.synchrony
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/genesis/reactor.rb', line 36 def run if running? initialize_protocols initialize_threadpool initialize_sighandlers return true else fail 'Must run from within reactor' end end |
#running? ⇒ Boolean
Check if the reactor is running
48 49 50 |
# File 'lib/genesis/reactor.rb', line 48 def running? EM.reactor_running? end |
#start ⇒ Object
Convenience wrapper to run indefinitely as daemon
29 30 31 32 33 |
# File 'lib/genesis/reactor.rb', line 29 def start EM.synchrony do run end end |
#stop ⇒ Object
Stop the reactor
53 54 55 56 |
# File 'lib/genesis/reactor.rb', line 53 def stop puts 'Shutting down' EM.stop end |