Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save hakobe/82701 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Coro::State;
use Perl6::Say;
my $resume;
my $yield;
my $func;
{
my $ret;
my $main;
my $state;
$main = Coro::State->new;
$state = Coro::State->new(sub {
$func->();
});
$resume = sub {
$main->transfer($state);
$ret;
};
$yield = sub {
$ret = shift;
$state->transfer($main);
};
}
$func = sub {
my $n = 0;
while (1) {
$yield->($n++);
}
};
say $resume->();
say $resume->();
say $resume->();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment