Created
April 26, 2011 14:48
-
-
Save kraih/942395 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $self = shift; | |
# Fresh singleton event loop | |
local $Mojo::IOLoop::LOOP = Mojo::IOLoop->new; | |
# Fresh useragent | |
my $ua = Mojo::UserAgent->new; | |
# Parallel blocking requests | |
my @results; | |
$ua->get('mojolicio.us' => sub { | |
push @results, pop; | |
Mojo::IOLoop->stop if @results > 1; | |
}); | |
$ua->get('blog.kraih.com' => sub { | |
push @results, pop; | |
Mojo::IOLoop->stop if @results > 1; | |
}); | |
Mojo::IOLoop->start; | |
# Done | |
my $titles = ''; | |
$titles .= $_->res->dom->at('title')->text for @results; | |
$self->render_text($titles); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment