Created
November 28, 2013 19:08
-
-
Save jberger/7696837 to your computer and use it in GitHub Desktop.
Simple Mojo::IOLoop::ForkCall example
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 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I couldn't get it to work on strawberry perl (windows xp):
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