lib/amqp.rb in tmm1-amqp-0.5.3 vs lib/amqp.rb in tmm1-amqp-0.5.5

- old
+ new

@@ -1,7 +1,7 @@ module AMQP - VERSION = '0.5.3' + VERSION = '0.5.5' DIR = File.expand_path(File.dirname(File.expand_path(__FILE__))) $:.unshift DIR require 'ext/em' @@ -12,44 +12,33 @@ end class << self @logging = false attr_accessor :logging - attr_reader :stopping end + def self.connect *args + Client.connect *args + end + def self.settings @settings ||= { :user => 'guest', :pass => 'guest', - :vhost => '/' + :vhost => '/', + :logging => false } end def self.start *args - @conn ||= Client.connect *args + @conn ||= connect *args end - def self.stop stop_reactor = true, &on_stop + def self.stop if @conn - @conn.callback{ |c| - if c.channels.keys.any? - c.channels.each do |_, mq| - mq.close - end - else - c.close - end - } - @on_stop = proc{ + @conn.close{ + yield if block_given? @conn = nil - on_stop.call if on_stop - EM.stop_event_loop if stop_reactor } end - end - - def self.stopped - @on_stop.call if @on_stop - @on_stop = nil end end \ No newline at end of file