Last active
August 29, 2015 14:03
-
-
Save jberger/bffa512fe1499b00a751 to your computer and use it in GitHub Desktop.
Pre 5.0 delay webapps
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; | |
get '/error' => sub { | |
my $c = shift; | |
$c->render_later; | |
my $delay = Mojo::IOLoop->delay( | |
sub { die 'Argh' }, | |
sub { $c->render( text => 'Lived!') }, | |
); | |
$delay->on( error => sub { $c->render_exception }); | |
$delay->wait unless $delay->ioloop->is_running; | |
}; | |
get '/pause' => sub { | |
my $c = shift; | |
$c->render_later; | |
my $delay = Mojo::IOLoop->delay( | |
sub { Mojo::IOLoop->timer(4 => shift->begin) }, | |
sub { $c->render(text => 'Hi after pause') if $c->tx }, | |
); | |
$delay->wait unless $delay->ioloop->is_running; | |
}; | |
app->start; | |
__DATA__ | |
@@ pause.html.ep | |
This isn't what you mean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment