| 1 |
$| = 1; |
| 2 |
print "1..13\n"; |
| 3 |
|
| 4 |
use AnyEvent; |
| 5 |
# 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 |
use AnyEvent::Fork::RPC; |
| 9 |
|
| 10 |
print "ok 1\n"; |
| 11 |
|
| 12 |
my $done = AE::cv; |
| 13 |
|
| 14 |
my $rpc = AnyEvent::Fork |
| 15 |
->new |
| 16 |
->eval (do { local $/; <DATA> }) |
| 17 |
->AnyEvent::Fork::RPC::run ("run", |
| 18 |
on_error => sub { print "Bail out! $_[0]\n"; exit 1 }, |
| 19 |
on_event => sub { print "$_[0]\n" }, |
| 20 |
on_destroy => $done, |
| 21 |
); |
| 22 |
|
| 23 |
print "ok 2\n"; |
| 24 |
|
| 25 |
for (3..6) { |
| 26 |
$rpc->($_ * 2 - 1, sub { print $_[0] }); |
| 27 |
} |
| 28 |
|
| 29 |
print "ok 3\n"; |
| 30 |
|
| 31 |
undef $rpc; |
| 32 |
|
| 33 |
print "ok 4\n"; |
| 34 |
|
| 35 |
$done->recv; |
| 36 |
|
| 37 |
print "ok 13\n"; |
| 38 |
|
| 39 |
__DATA__ |
| 40 |
|
| 41 |
sub run { |
| 42 |
my ($count) = @_; |
| 43 |
|
| 44 |
AnyEvent::Fork::RPC::event ("ok $count"); |
| 45 |
|
| 46 |
"ok " . ($count + 1) . "\n" |
| 47 |
} |
| 48 |
|