lib/bunny/session.rb in bunny-1.1.0.pre2 vs lib/bunny/session.rb in bunny-1.1.0.rc1
- old
+ new
@@ -271,10 +271,12 @@
# thread until the response is received and the channel is guaranteed to be
# opened (this operation is very fast and inexpensive).
#
# @return [Bunny::Channel] Newly opened channel
def create_channel(n = nil, consumer_pool_size = 1)
+ raise ArgumentError, "channel number 0 is reserved in the protocol and cannot be used" if 0 == n
+
if n && (ch = @channels[n])
ch
else
ch = Bunny::Channel.new(self, n, ConsumerWorkPool.new(consumer_pool_size || 1))
ch.open
@@ -305,11 +307,14 @@
# method and closes it.
#
# @return [Bunny::Session] self
def with_channel(n = nil)
ch = create_channel(n)
- yield ch
- ch.close if ch.open?
+ begin
+ yield ch
+ ensure
+ ch.close if ch.open?
+ end
self
end
# @return [Boolean] true if this connection is still not fully open