| 1 |
root |
1.1 |
$| = 1; |
| 2 |
|
|
print "1..63\n"; |
| 3 |
|
|
|
| 4 |
|
|
use AnyEvent; |
| 5 |
root |
1.2 |
# explicit version on next line, as some cpan-testers test with the 0.1 version, |
| 6 |
|
|
# ignoring dependencies, and this line will at least give a clear indication of that. |
| 7 |
|
|
use AnyEvent::Fork 0.6; # we don't actually depend on it, this is for convenience |
| 8 |
root |
1.1 |
use AnyEvent::Fork::Pool; |
| 9 |
|
|
|
| 10 |
|
|
print "ok 1\n"; |
| 11 |
|
|
|
| 12 |
|
|
# all parameters with default values |
| 13 |
|
|
my $pool = AnyEvent::Fork |
| 14 |
|
|
->new |
| 15 |
|
|
->eval (do { local $/; <DATA> }) |
| 16 |
|
|
->AnyEvent::Fork::Pool::run ( |
| 17 |
|
|
"run", # the worker function |
| 18 |
|
|
|
| 19 |
|
|
on_destroy => (my $finish = AE::cv), # called when object is destroyed |
| 20 |
|
|
); |
| 21 |
|
|
|
| 22 |
|
|
print "ok 2\n"; |
| 23 |
|
|
|
| 24 |
|
|
for (1..30) { |
| 25 |
|
|
$pool->(doit => $_, sub { |
| 26 |
|
|
print "ok # return\n"; |
| 27 |
|
|
}); |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
undef $pool; |
| 31 |
|
|
|
| 32 |
|
|
$finish->recv; |
| 33 |
|
|
|
| 34 |
|
|
print "ok 63\n"; |
| 35 |
|
|
|
| 36 |
|
|
__DATA__ |
| 37 |
|
|
|
| 38 |
|
|
sub run { |
| 39 |
|
|
print "ok # run\n"; |
| 40 |
|
|
select undef, undef, undef, rand 0.2; |
| 41 |
|
|
AnyEvent::Fork::Pool::retire() if rand > 0.5; |
| 42 |
|
|
1 |
| 43 |
|
|
} |
| 44 |
|
|
|