Skip to content

Instantly share code, notes, and snippets.

@beppu
Created July 13, 2009 10:57
Show Gist options
  • Select an option

  • Save beppu/146042 to your computer and use it in GitHub Desktop.

Select an option

Save beppu/146042 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Coro;
use Coro::AnyEvent;
use Coro::Semaphore;
use AnyEvent;
my @coros;
my $s = Coro::Semaphore->new;
for my $i (1..5) {
$s->down;
push @coros, async {
my $w = AnyEvent->condvar;
my $t = AnyEvent->timer(after => $i, cb => sub { $w->send });
$w->recv;
$s->up;
warn "done $i";
};
}
async { $s->wait; warn "all done"; exit };
AnyEvent->condvar->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment