Skip to content

Instantly share code, notes, and snippets.

@mpapec
Forked from jberger/test.pl
Last active September 8, 2016 14:57
Show Gist options
  • Save mpapec/434884dcf7094468096017ad4e05860e to your computer and use it in GitHub Desktop.
Save mpapec/434884dcf7094468096017ad4e05860e to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
helper iodelay => sub {
my $cb = pop;
my ($c, @steps) = @_;
push @steps, sub {
# log err if $_[1]
shift;
$c->$cb(@_);
};
Mojo::IOLoop->delay(@steps)->catch($steps[-1]);
};
any '/' => sub {
my $c = shift;
$c->iodelay(
sub{
my $delay = shift;
$delay->pass(text => 'hello world');
Mojo::IOLoop->timer(1 => $delay->begin);
},
sub {
my (undef, $err, @args) = @_;
$c->reply->exception($err) if $err;
$c->render(@args);
},
);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment