Skip to content

Instantly share code, notes, and snippets.

@jberger
Created November 28, 2013 19:08
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 jberger/7696837 to your computer and use it in GitHub Desktop.
Save jberger/7696837 to your computer and use it in GitHub Desktop.
Simple Mojo::IOLoop::ForkCall example
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::IOLoop::ForkCall;
any '/' => sub {
my $c = shift;
$c->render_later;
my $tick = 0;
my $r = Mojo::IOLoop->recurring( 1 => sub { $tick++ });
my $fc = Mojo::IOLoop::ForkCall->new;
$fc->run(
sub {
sleep 3;
return 'Hello from child', $$;
},
sub {
my ($fc, $err, $msg, $pid) = @_;
Mojo::IOLoop->remove($r);
$c->render(text => "$msg $pid after $tick ticks");
}
);
};
app->start;
@dmanto
Copy link

dmanto commented Mar 2, 2014

Hi, I couldn't get it to work on strawberry perl (windows xp):

C:\.....>perl child.pl get /

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

BTW, in linux (ubuntu) same code works perfect, also with morbo and hypnotoad

I "DuckDuckGoed" a little about this problem, and its like windows stops because the application finishes with an abort() c function.

Anyway Mojo::IOLoop::ForkCall does load ok from CPAN in strawberry perl (5.18.2), and looking at the tests I tried for instance big_send.t and it passes whith no problems at all. But there is no use Mojolicious nor use Mojolicious::Lite on the test, so probably it is not really effective to reproduce the problem.

Thanks in advance!
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment