Last active
December 17, 2015 13:59
-
-
Save tempire/5621542 to your computer and use it in GitHub Desktop.
Non-blocking request within a Mojolicious app
This file contains hidden or 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
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