Created
December 4, 2012 16:16
-
-
Save tadzik/4205696 to your computer and use it in GitHub Desktop.
This file contains 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
┌─[tadzik@yavin4]─[~] | |
└─[%]─> cat coro.pl | |
use LWP::Simple; | |
sub yield { take 1 } | |
class Fakesocket is IO::Socket::INET { | |
method recv($) { | |
yield; | |
callsame; | |
} | |
method read($) { | |
yield; | |
callsame; | |
} | |
} | |
sub blackbox($lwp) { | |
my $a = $lwp.get("http://jigsaw.w3.org/HTTP/300/301.html"); | |
} | |
my $lwp = LWP::Simple.new(socketclass => Fakesocket); | |
say "Silence before the storm"; | |
my @a := gather { blackbox($lwp); take "done"; } | |
say "Now running the blackbox"; | |
@a.shift; | |
say "Now doing the actual receiving"; | |
while ~@a.shift ne "done" { | |
say "The coroutine is still running. Let's have a tea while waiting" | |
} | |
say "Yeah, we did it!" | |
┌─[tadzik@yavin4]─[~] | |
└─[%]─> perl6 coro.pl | |
Silence before the storm | |
Now running the blackbox | |
Now doing the actual receiving | |
The coroutine is still running. Let's have a tea while waiting | |
The coroutine is still running. Let's have a tea while waiting | |
The coroutine is still running. Let's have a tea while waiting | |
Yeah, we did it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment