Skip to content

Instantly share code, notes, and snippets.

@olegwtf
Created January 12, 2012 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegwtf/1601965 to your computer and use it in GitHub Desktop.
Save olegwtf/1601965 to your computer and use it in GitHub Desktop.
IO::Lambda::HTTP
use strict;
use URI;
use HTTP::Request;
use IO::Lambda qw(:all);
use IO::Lambda::HTTP qw(http_request);
sub request($) {
my $url = URI->new($_[0]);
my $req = HTTP::Request->new(GET => $url, [Host => $url->host]);
$req->protocol('HTTP/1.1');
$req;
}
par->wait(
map {
my $request = request $_;
lambda {
context $request;
http_request {
my $response = shift;
if (ref $response) {
print $request->url, ': ', $response->status_line, "\n";
}
else {
print $request->url, ': ', $response, "\n";
}
}
}
} qw(http://perlmonks.org http://www.google.ru/ http://perl.org/ http://perl.com)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment