Created
July 27, 2013 18:42
-
-
Save Incanus3/6095839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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