Skip to content

Instantly share code, notes, and snippets.

@simonecesano
Last active January 4, 2018 21:06
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 simonecesano/0ed2163c2ba4e635d458611963027762 to your computer and use it in GitHub Desktop.
Save simonecesano/0ed2163c2ba4e635d458611963027762 to your computer and use it in GitHub Desktop.
Render and then do slow things inside Mojolicious::Lite app
get '/timer' => sub {
my $c = shift;
# $c->render_later; not needed
my $delay = Mojo::IOLoop->delay(sub {
$c->app->log->info('Delay finished!');
$c->render(text => 'timer!');
});
$delay->begin->();
for my $i (0 .. 5) {
app->log->info("outside timer " . $i);
Mojo::IOLoop->timer(0 => sub {
app->log->info('in timer ' . $i);
});
}
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment