lib/amqp.rb in amqp-0.7.0.pre vs lib/amqp.rb in amqp-0.7.0
- old
+ new
@@ -1,8 +1,10 @@
+# encoding: utf-8
+
require File.expand_path('../ext/em', __FILE__)
require File.expand_path('../ext/blankslate', __FILE__)
-
+
%w[ version buffer spec protocol frame client ].each do |file|
require File.expand_path("../amqp/#{file}", __FILE__)
end
module AMQP
@@ -74,28 +76,30 @@
# MQ.topic / MQ.queue will implicitly call #start. In those cases,
# it is sufficient to put your code inside of an EventMachine.run
# block. See the code examples in MQ for details.
#
def self.start *args, &blk
- EM.run{
+ EM.run {
@conn ||= connect *args
@conn.callback(&blk) if blk
@conn
}
end
class << self
alias :run :start
end
-
+
def self.stop
if @conn and not @closing
@closing = true
- @conn.close{
- yield if block_given?
- @conn = nil
- @closing = false
- }
+ EM.next_tick do
+ @conn.close {
+ yield if block_given?
+ @conn = nil
+ @closing = false
+ }
+ end
end
end
def self.fork workers
EM.fork(workers) do