Skip to content

Instantly share code, notes, and snippets.

@oetiker
Created July 23, 2014 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oetiker/f9d26a4389ddd28ca438 to your computer and use it in GitHub Desktop.
Save oetiker/f9d26a4389ddd28ca438 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::IOLoop::ForkCall 'fork_call';
for my $id (1..2) {
fork_call(
sub {
sleep 1;
return "PID: $$ my id is $_[0]";
},
$id,
sub {
die "PID $$: ".$@ if $@; # error
say $_[0]; # "my id is ..."
},
);
};
Mojo::IOLoop->start;
(in cleanup) Mojo::IOLoop::Stream: Event "close" failed: PID 9692: Magic number checking on storable string failed at /usr/pack/perl-ubuntu1204amd64-5.16.2-rp/lib/perl/x86_64-linux-thread-multi/Storable.pm line 417, at /home/oetiker/checkouts/znapzend/bin/../thirdparty/lib/perl5/Mojo/IOLoop/ForkCall.pm line 80.
PID: 9691 my id is 1
PID: 9692 my id is 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment