Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created December 4, 2012 16:16
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 tadzik/4205696 to your computer and use it in GitHub Desktop.
Save tadzik/4205696 to your computer and use it in GitHub Desktop.
┌─[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