From 40fa9641cea4101affbbcc68a052022154e30859 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 29 Aug 2011 15:35:16 +0200 Subject: [PATCH] Fix a bug when closing a channel that is subscribed to multiple queues --- lib/AnyEvent/RabbitMQ/Channel.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/AnyEvent/RabbitMQ/Channel.pm b/lib/AnyEvent/RabbitMQ/Channel.pm index d800768..c1876c8 100644 --- a/lib/AnyEvent/RabbitMQ/Channel.pm +++ b/lib/AnyEvent/RabbitMQ/Channel.pm @@ -57,16 +57,19 @@ sub close { return $self if !$self->{_is_open}; - return $self->_close(%args) if 0 == scalar keys %{$self->{_consumer_cbs}}; + my %cbs = %{ $self->{_consumer_cbs} }; + return $self->_close(%args) unless %cbs; - for my $consumer_tag (keys %{$self->{_consumer_cbs}}) { + for my $consumer_tag ( keys %cbs ) { $self->cancel( consumer_tag => $consumer_tag, on_success => sub { - $self->_close(%args); + delete $cbs{$consumer_tag}; + $self->_close(%args) unless %cbs; }, - on_failure => sub { - $self->_close(%args); + on_failure => sub { + delete $cbs{$consumer_tag}; + $self->_close(%args) unless %cbs; $args{on_failure}->(@_); } );