Skip to content

Instantly share code, notes, and snippets.

@phluks
Created Oct 23, 2012
Embed
What would you like to do?
Perl AnyEvent: How to make async calls in a loop - oh, this seems to work.
use AnyEvent;
use AnyEvent::Util qw"run_cmd";
sub f {
my($x) = @_;
warn "got (($x))\n";
};
for my $n (1..10) {
my $rand = int(rand(10));
$run = run_cmd "sleep $rand; echo $n", ">", \&f;
#$run->recv;
}
$run->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment