Skip to content

Instantly share code, notes, and snippets.

Created Oct 23, 2012
What would you like to do?
Perl AnyEvent: How to make async calls in a loop?
use strict;
use warnings;
use v5.10;
use AnyEvent;
use AnyEvent::Util;
# OBS: This doesn't work!
for my $n (1..100) {
my $rand = int(rand(10));
my $hdl;
$hdl = AnyEvent::io (
fh => \*STDIN,
poll => 'r',
cb => sub {
my $str = `sleep $rand; echo $n`;
# Hmm - args
sub output {
my $n = shift;
say "Got: $n";
illegal file descriptor or filehandle (either no attached file descriptor or illegal value): at /usr/local/lib64/perl5/AnyEvent/Impl/ line 55.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment