On 4 Aug 2000, Perl6 RFC Librarian wrote:
> This proposal introduces a new keyword to perl, "co", as a complement
> to "sub". A subroutine is defined thusly:
>
> co foo { ... }
>
> Coroutines can also be closures:
>
> my $x = co { ... }
Does this really require a new keyword? Why not do it as a module:
use Coroutine;
my $foo = new Coroutine(sub => sub { ... });
# to send
print $foo "data\n";
# to read
my $val = <$foo>;
This also allows a much easier path to future expansion. You can add new
options to new() easily - a priority option is something you
mentioned. You could also setup martialling if such is required.
> Coroutines can be implemented in their traditional manner, using context
> switching, or as threads, but would hide the mundane details of threads
> from the programmer. They would be more suited for producer/consumer type
> problems rather than massively parallel compuations, but I doubt there is
> much call for the latter to be implemented in perl.
And, of course, this wouldn't be the only threading primative offered by
Perl!
Other than those points, this RFC has my whole-hearted support. I'd love
to see solid coroutine support in Perl.
-sam