Last active
August 29, 2015 13:56
-
-
Save tempire/9143087 to your computer and use it in GitHub Desktop.
delay around_action tx scope mojolicious
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
use Mojolicious::Lite; | |
use Mojo::IOLoop::Delay; | |
hook around_action => sub { | |
my ($next, $c, $action, $last) = @_; | |
$c->stash->{tx} = $c->tx; # Maintain scope | |
return $next->() if not $last; | |
my $delay = Mojo::IOLoop::Delay->new; | |
$c->render_later; | |
$delay->steps( | |
sub { | |
$c->app->log->debug('first step'); | |
$delay->begin->(); | |
}, | |
sub { | |
$c->tx->on( | |
finish => sub { | |
$delay->begin->(); | |
} | |
); | |
$next->(); | |
}, | |
sub { | |
$c->app->log->debug('3rd step'); | |
} | |
); | |
}; | |
get '/' => sub { | |
my $self = shift; | |
# Mojolicious::Controller | |
warn ref $self->req; | |
$self->render(text => "gotten"); | |
warn ref $self->req; | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment