Skip to content

Instantly share code, notes, and snippets.

@sng2c
Created June 21, 2012 09:04
Show Gist options
  • Save sng2c/2964717 to your computer and use it in GitHub Desktop.
Save sng2c/2964717 to your computer and use it in GitHub Desktop.
coupled timer fail
use AnyEvent;
use EV;
my $cv = AE::cv;
my $t = AE::timer 2,0, sub{
my $cv2 = AE::cv;
my $cnt = 10;
my $tot = 0;
foreach(1..10){
my $idx = $_;
my $tt; $tt = AE::timer 1,0,sub{
print "t $idx\n";
$tot+=$idx;
$cnt--;
undef($tt);
}
}
while($cnt){
AnyEvent->_poll;
print "t idle\n";
} # wait
print "t tot: $tot\n";
};
my $t2= AE::timer 2,0, sub{
my $cv2 = AE::cv;
my $cnt = 10;
my $tot = 0;
foreach(1..10){
my $idx = $_;
my $tt; $tt = AE::timer $idx,0,sub{
print "t2 $idx\n";
$tot+=$idx;
$cnt--;
undef($tt);
}
}
while($cnt){
AnyEvent->_poll;
print "t2 idle\n";
} # wait
print "t2 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