Skip to content

@jnthn /gist:11126125
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
sub crappy_async_lwp($host, $path) {
my $p = Promise.new;
my $v = $p.vow;
IO::Socket::Async.connect($host, 80).then(-> $sr {
if $sr.status == Kept {
my $socket = $sr.result;
$socket.send("GET $path\r\n\r\n").then(-> $wr {
if $wr.status == Broken {
$v.break($wr.cause);
$socket.close();
}
});
my @chunks;
$socket.chars_supply.tap(
{ @chunks.push($_) },
done => {
$socket.close();
$v.keep(@chunks.join());
},
quit => { $v.break($_); });
}
else {
$v.break($sr.cause);
}
});
$p;
}
say await crappy_async_lwp('www.jnthn.net', '/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.