Class: RenderSync::Reactor
- Inherits:
-
Object
- Object
- RenderSync::Reactor
- Includes:
- MonitorMixin
- Defined in:
- lib/render_sync/reactor.rb
Instance Method Summary collapse
-
#cleanly_shutdown_reactor ⇒ Object
If the reactor’s thread died, EM still thinks it’s running but it isn’t.
-
#perform ⇒ Object
Execute EventMachine bound code block, waiting for reactor to start if not yet started or reactor thread has gone away.
- #running? ⇒ Boolean
- #stop ⇒ Object
Instance Method Details
#cleanly_shutdown_reactor ⇒ Object
If the reactor’s thread died, EM still thinks it’s running but it isn’t. This will happen if we forked from a process that had the reator running. Tell EM it’s dead. Stolen from the EM internals
groups.google.com/forum/#!msg/ruby-amqp/zchM4QzbZRE/I43wIjbgIv4J
40 41 42 43 44 45 46 |
# File 'lib/render_sync/reactor.rb', line 40 def cleanly_shutdown_reactor if EM.reactor_running? EM.stop_event_loop EM.release_machine EM.instance_variable_set '@reactor_running', false end end |
#perform ⇒ Object
Execute EventMachine bound code block, waiting for reactor to start if not yet started or reactor thread has gone away
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/render_sync/reactor.rb', line 7 def perform return EM.next_tick{ yield } if running? cleanly_shutdown_reactor condition = new_cond Thread.new do EM.run do EM.next_tick do synchronize do condition.signal end end end end synchronize do condition.wait_until { EM.reactor_running? } EM.next_tick { yield } end end |
#running? ⇒ Boolean
30 31 32 |
# File 'lib/render_sync/reactor.rb', line 30 def running? EM.reactor_running? && EM.reactor_thread.alive? end |
#stop ⇒ Object
26 27 28 |
# File 'lib/render_sync/reactor.rb', line 26 def stop EM.stop if running? end |