-
-
Save yko/905869 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use List::Util qw/reduce/; | |
use Mojolicious::Lite; | |
use Mojo::UserAgent; | |
use Mojo::IOLoop; | |
get '/async' => sub { my $self = shift; my $ua = $self->ua; $ua->ioloop(Mojo::IOLoop->singleton); $ua->get('http://google.com' => cb($self)); $ua->get('http://ya.ru' => cb($self)); $self->render_later; }; sub cb { my $c = shift; my $output = \@{$c->{_output}}; return sub { my ( $ua, $tx ) = @_; push @$output, $tx->req->url->to_string; | |
if (@$output >= 2) { $c->render(text => join "\n", @$output); } }; } app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment