Skip to content

Instantly share code, notes, and snippets.

@phluks
Created October 23, 2012 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phluks/3938301 to your computer and use it in GitHub Desktop.
Save phluks/3938301 to your computer and use it in GitHub Desktop.
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