-
-
Save oetiker/bbd3e468b0d25815738c to your computer and use it in GitHub Desktop.
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 FindBin; | |
# PERL5LIB | |
use lib "$FindBin::Bin/../lib"; | |
use lib "$FindBin::Bin/../thirdparty/lib/perl5"; | |
use Mojo::IOLoop::ForkCall; | |
use Data::Dumper; | |
my @fc; | |
for my $id (1..2) { | |
my $fc = Mojo::IOLoop::ForkCall->new; | |
push @fc, $fc; #keep fc in scope | |
my $pid = $fc->run( | |
sub { | |
my $arg = shift; | |
warn "$id ($$): start sleep\n"; | |
sleep 2; | |
warn "$id ($$): end sleep\n"; | |
return ({complex=>'data',id=>$id},$arg); | |
}, | |
["Scalar $id"], | |
sub { | |
my ($fc, $err, @return) = @_; | |
warn "$id ($$): return: ".Dumper \@return; | |
warn "$id ($$): error: $err\n" if $err; | |
} | |
); | |
}; | |
Mojo::IOLoop->start; |
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
1 (8444): start sleep | |
1 (8445): return: $VAR1 = []; | |
1 (8445): error: Magic number checking on storable string failed at /usr/lib/perl/5.14/Storable.pm line 416, at /home/oetiker/checkouts/znapzend/bin/../thirdparty/lib/perl5/Mojo/IOLoop/ForkCall.pm line 80 | |
2 (8445): start sleep | |
1 (8444): end sleep | |
1 (8443): return: $VAR1 = [ | |
{ | |
'complex' => 'data', | |
'id' => '1' | |
}, | |
'Scalar 1' | |
]; | |
2 (8445): end sleep | |
2 (8443): return: $VAR1 = [ | |
{ | |
'complex' => 'data', | |
'id' => '2' | |
}, | |
'Scalar 2' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment