Skip to content

Instantly share code, notes, and snippets.

@tempire
Last active December 17, 2015 13:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tempire/5621542 to your computer and use it in GitHub Desktop.
Save tempire/5621542 to your computer and use it in GitHub Desktop.
Non-blocking request within a Mojolicious app
get '/' => sub {
my $self = shift;
my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx(GET => 'http://tempi.re');
$tx->on(finish => sub {
my $tx = pop;
warn $tx->error; # premature connection close
$self->render(text => $tx->res->body);
});
$ua->start($tx);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment