Skip to content

Instantly share code, notes, and snippets.

@Incanus3
Created July 27, 2013 18:42
Show Gist options
  • Save Incanus3/6095839 to your computer and use it in GitHub Desktop.
Save Incanus3/6095839 to your computer and use it in GitHub Desktop.
require 'eventmachine'
EventLoopNotRunning = Class.new(StandardError)
class AMQPHelper
def initialize
raise EventLoopNotRunning unless EM.reactor_running?
end
def self.start_reactor(&block)
Thread.new { EM.run(&block) }
sleep(0.1) until EM.reactor_running?
end
def self.stop_reactor
EM.next_tick {
# puts "stopping reactor";
EM.stop } if EM.reactor_running?
begin
p EM.reactor_running?
sleep(0.1)
end while EM.reactor_running? unless EM.reactor_thread?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment