class RenderSync::Reactor

Public Instance Methods

cleanly_shutdown_reactor() click to toggle source

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

# 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() { || ... } click to toggle source

Execute EventMachine bound code block, waiting for reactor to start if not yet started or reactor thread has gone away

# 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?() click to toggle source
# File lib/render_sync/reactor.rb, line 30
def running?
  EM.reactor_running? && EM.reactor_thread.alive?
end
stop() click to toggle source
# File lib/render_sync/reactor.rb, line 26
def stop
  EM.stop if running?
end