Created
February 6, 2017 20:13
-
-
Save dwburke/e2de16038a57b7040ab55cf77fe7a337 to your computer and use it in GitHub Desktop.
Simple fork job queue with AnyEvent fork_call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use AnyEvent; | |
use AnyEvent::Util; | |
my $cv = AnyEvent->condvar; | |
$AnyEvent::Util::MAX_FORKS = 5; | |
my $fork_jobs = 0; | |
for (my $i = 0; $i < 20; $i++) { | |
$fork_jobs++; | |
fork_call { | |
# your job here | |
return $$; | |
} sub { | |
($a) = @_; | |
print $a . "\n"; # your result output here | |
$cv->send if $fork_jobs == 0; | |
}; | |
} | |
$cv->wait; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment