Skip to content

Instantly share code, notes, and snippets.

@yowcow
Created January 19, 2016 12:46
Show Gist options
  • Save yowcow/8292183ad0ef4f740a25 to your computer and use it in GitHub Desktop.
Save yowcow/8292183ad0ef4f740a25 to your computer and use it in GitHub Desktop.
Parallel HTTP request in Perl 6
use v6;
use HTTP::UserAgent;
use HTTP::Request;
use Test;
use URI;
my Str @urls = "http://hoge.fuga/",
"http://fuga.hoge/",
"http://fooo.baar/";
my Promise @p = (for @urls -> $url {
my URI $uri .= new($url);
start {
say "Making request to $url...";
my HTTP::UserAgent $ua .= new;
my HTTP::Response $res = $ua.request(HTTP::Request.new(GET => $uri));
say "Got response from $url with status code: {$res.code}";
"URL: $url (Code: {$res.code})";
}
});
await @p;
my Str @result = @p>>.result;
is @result.elems, 3;
done-testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment