Perl6-GatherTake
view release on metacpan or search on metacpan
lib/Perl6/GatherTake.pm view on Meta::CPAN
use base 'Exporter';
use Perl6::GatherTake::LazyList;
use Coro;
use Coro::Channel;
use Carp qw(confess);
use Scalar::Util qw(refaddr);
our @EXPORT = qw(gather take);
our %_coro_to_queue;
sub gather(&@) {
my $code = shift;
# cheat prototype by prepending '&' to method call:
my $coro = &async($code, @_);
my @result = ();
my $queue = Coro::Channel->new(1);
# print "Initialized coro $coro\n";
$_coro_to_queue{refaddr($coro)} = $queue;
tie @result, 'Perl6::GatherTake::LazyList', $coro, $queue;
return \@result;
}
( run in 0.249 second using v1.01-cache-2.11-cpan-49f99fa48dc )