lib/amqp.rb in tmm1-amqp-0.5.5 vs lib/amqp.rb in tmm1-amqp-0.5.9
- old
+ new
@@ -1,7 +1,7 @@
module AMQP
- VERSION = '0.5.5'
+ VERSION = '0.5.9'
DIR = File.expand_path(File.dirname(File.expand_path(__FILE__)))
$:.unshift DIR
require 'ext/em'
@@ -12,30 +12,52 @@
end
class << self
@logging = false
attr_accessor :logging
+ attr_reader :conn, :closing
+ alias :connection :conn
end
def self.connect *args
Client.connect *args
end
def self.settings
@settings ||= {
+ # server address
+ :host => '127.0.0.1',
+ :port => PORT,
+
+ # login details
:user => 'guest',
:pass => 'guest',
:vhost => '/',
+
+ # connection timeout
+ :timeout => nil,
+
+ # logging
:logging => false
}
end
- def self.start *args
- @conn ||= connect *args
+ def self.start *args, &blk
+ EM.run{
+ @conn ||= connect *args
+ @conn.callback(&blk) if blk
+ @conn
+ }
end
+
+ class << self
+ alias :run :start
+ end
def self.stop
if @conn
+ puts "Shutting down..."
+ @closing = true
@conn.close{
yield if block_given?
@conn = nil
}
end
\ No newline at end of file