Skip to content

Instantly share code, notes, and snippets.

@sng2c
Created June 21, 2012 08:27
Show Gist options
  • Save sng2c/2964586 to your computer and use it in GitHub Desktop.
Save sng2c/2964586 to your computer and use it in GitHub Desktop.
solve local blocking
use AnyEvent;
my $cv = AE::cv;
my $t = AE::timer 2,0, sub{
my $cv2 = AE::cv;
my $cnt = 10;
my $tot = 0;
my $done = 0;
$cv2->begin(sub{$done=1;});
foreach(1..10){
my $idx = $_;
$cv2->begin;
my $tt; $tt = AE::timer $idx,0,sub{
print "$idx\n";
$tot+=$idx;
$cnt--;
$cv2->end;
undef($tt);
}
}
$cv2->end;
until($done){
AnyEvent->_poll;
print "idle\n";
} # wait
print "tot: $tot\n";
};
$cv->recv;
print "DONE\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment