Skip to content

Instantly share code, notes, and snippets.

@tempire
Last active August 29, 2015 13:56
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 tempire/9143087 to your computer and use it in GitHub Desktop.
Save tempire/9143087 to your computer and use it in GitHub Desktop.
delay around_action tx scope mojolicious
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