You block script execution when you call $ cv-> recv (), while the loop and script wait for $ cv-> send or $ cv-> croak, but you do not call $ cv β Send () on the callback.
$ cv-> recv
Wait (if necessary, block) until the methods β send or β croak are called in $ cv, usually serving other observers.
, AnyEvents.
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
use strict;
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => '6379',
);
my $i=0;
my $cv = AnyEvent->condvar;
while($i++ < 5) {
$cv->begin;
$redis->rpush( 'list', "1","2","3",
{
on_done => sub {
my $data = shift;
print "$data\n";
$cv->end();
},
}
);
}
$cv->recv();