Created
April 20, 2014 21:49
-
-
Save jnthn/11126125 to your computer and use it in GitHub Desktop.
Revisions
-
jnthn created this gist
Apr 20, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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', '/');