[libanyevent-rabbitmq-perl] 128/151: Fix use of a condvar in the close method
Damyan Ivanov
dmn at moszumanska.debian.org
Thu Jan 16 11:03:10 UTC 2014
This is an automated email from the git hooks/post-receive script.
dmn pushed a commit to annotated tag debian/1.12-1
in repository libanyevent-rabbitmq-perl.
commit 192b417742ed52ae1656dec325e46059f74d30bb
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Mon Feb 25 11:51:07 2013 +0000
Fix use of a condvar in the close method
---
lib/AnyEvent/RabbitMQ.pm | 46 ++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/lib/AnyEvent/RabbitMQ.pm b/lib/AnyEvent/RabbitMQ.pm
index 25169cb..1fab2a9 100644
--- a/lib/AnyEvent/RabbitMQ.pm
+++ b/lib/AnyEvent/RabbitMQ.pm
@@ -7,6 +7,7 @@ use List::MoreUtils qw(none);
use Devel::GlobalDestruction;
use File::ShareDir;
use Readonly;
+use Scalar::Util qw/ weaken /;
use namespace::clean;
require Data::Dumper;
@@ -308,7 +309,7 @@ sub _open {
virtual_host => $args{vhost},
insist => 1,
},
- 'Connection::OpenOk',
+ 'Connection::OpenOk',
sub {
$self->{_is_open} = 1;
$self->{_login_user} = $args{user};
@@ -322,6 +323,8 @@ sub _open {
sub close {
my $self = shift;
+ my $weak_self = $self;
+ weaken($weak_self);
my %args = $self->_set_cbs(@_);
if (!$self->{_is_open}) {
@@ -329,40 +332,39 @@ sub close {
return $self;
}
- my $channels_cv = AnyEvent->condvar;
- $channels_cv->begin(
- sub {
- $self->_close(
- sub {
- $self->_disconnect();
- $args{on_success}->(@_);
- },
- sub {
- $self->_disconnect();
- $args{on_failure}->(@_);
- }
- );
- }
- );
-
+ my $channels_to_close = 0;
+ my $all_closed_cb = sub {
+ return unless 0 == $channels_to_close;
+ $weak_self->_close(
+ sub {
+ $weak_self->_disconnect();
+ $args{on_success}->(@_);
+ },
+ sub {
+ $weak_self->_disconnect();
+ $args{on_failure}->(@_);
+ }
+ );
+ };
for my $id (keys %{$self->{_channels}}) {
my $channel = $self->{_channels}->{$id}
or next; # Could have already gone away on global destruction..
- $channels_cv->begin;
+ $channels_to_close++;
+
$channel->close(
on_success => sub {
- $channels_cv->end;
+ $channels_to_close--;
+ $all_closed_cb->();
},
on_failure => sub {
- $channels_cv->end;
+ $channels_to_close--;
+ $all_closed_cb->();
$args{on_failure}->(@_);
},
);
}
- $channels_cv->end;
-
return $self;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libanyevent-rabbitmq-perl.git
More information about the Pkg-perl-cvs-commits
mailing list