Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
earliest example
  • Loading branch information
jonathanstowe committed Apr 28, 2015
1 parent 1732101 commit 6368d45
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/Language/concurrency.pod
Expand Up @@ -370,6 +370,34 @@ The L<method closed|/type/Channel#method_closed> returns a L<Promise> that
will be kept (and consequently will evaluate to True in a boolean context,)
when the channel is closed.
Because looping over a channel in this manner is a common pattern there is
a simpler fumctional syntax to do this:
my $channel = Channel.new;
start {
loop {
earliest $channel {
more * {
say $_;
}
done * {
last;
}
}
}
}
await (^10).map: -> $r {
start {
sleep $r;
$channel.send($r);
}
}
$channel.close;
=head1 Low-level APIs
=head2 Threads
Expand Down

0 comments on commit 6368d45

Please sign in to comment.