Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created March 21, 2009 02:11
Show Gist options
  • Select an option

  • Save hakobe/82696 to your computer and use it in GitHub Desktop.

Select an option

Save hakobe/82696 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Coro;
use Coro::Channel;
use Perl6::Say;
my $resume;
my $yield;
my $func;
{
my $ch = Coro::Channel->new;
$resume = sub {
cede;
$ch->get;
};
$yield = sub {
$ch->put(shift);
cede;
};
async {
$func->();
};
}
$func = sub {
my $n = 0;
while (1) {
$yield->($n++);
}
};
say $resume->(); # 0
say $resume->(); # 1
say $resume->(); # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment