| 1 |
$| = 1; |
| 2 |
print "1..63\n"; |
| 3 |
|
| 4 |
use AnyEvent; |
| 5 |
use AnyEvent::Fork::Pool; |
| 6 |
|
| 7 |
print "ok 1\n"; |
| 8 |
|
| 9 |
# all parameters with default values |
| 10 |
my $pool = AnyEvent::Fork |
| 11 |
->new |
| 12 |
->eval (do { local $/; <DATA> }) |
| 13 |
->AnyEvent::Fork::Pool::run ( |
| 14 |
"run", # the worker function |
| 15 |
|
| 16 |
on_destroy => (my $finish = AE::cv), # called when object is destroyed |
| 17 |
); |
| 18 |
|
| 19 |
print "ok 2\n"; |
| 20 |
|
| 21 |
for (1..30) { |
| 22 |
$pool->(doit => $_, sub { |
| 23 |
print "ok # return\n"; |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
undef $pool; |
| 28 |
|
| 29 |
$finish->recv; |
| 30 |
|
| 31 |
print "ok 63\n"; |
| 32 |
|
| 33 |
__DATA__ |
| 34 |
|
| 35 |
sub run { |
| 36 |
print "ok # run\n"; |
| 37 |
select undef, undef, undef, rand 0.2; |
| 38 |
AnyEvent::Fork::Pool::retire() if rand > 0.5; |
| 39 |
1 |
| 40 |
} |
| 41 |
|