Class: Graphite::EventMachineHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite/event_machine_handler.rb

Class Method Summary collapse

Class Method Details

.ensure_runningObject



7
8
9
# File 'lib/graphite/event_machine_handler.rb', line 7

def self.ensure_running
  start_em unless EventMachine.reactor_running? 
end

.start_emObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphite/event_machine_handler.rb', line 13

def self.start_em
  em = Thread.new { EM.run{} }

  # We want to fail if there is an exception in EM otherwise we're dead in the water
  em.abort_on_exception = true

  %w(INT TERM).each do |sig|
    old = trap(sig) do 
      EM.stop if EM.reactor_running?

      if old.respond_to? :call
        old.call
      else
        old
      end
    end
  end
end