Class: RenderSync::Reactor

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/render_sync/reactor.rb

Instance Method Summary collapse

Instance Method Details

#cleanly_shutdown_reactorObject

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

#performObject

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/render_sync/reactor.rb', line 30

def running?
  EM.reactor_running? && EM.reactor_thread.alive?
end

#stopObject



26
27
28
# File 'lib/render_sync/reactor.rb', line 26

def stop
  EM.stop if running?
end