Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More channel
  • Loading branch information
jonathanstowe committed Apr 28, 2015
1 parent 4331ec1 commit 1d73e2a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Language/concurrency.pod
Expand Up @@ -339,6 +339,37 @@ channel is closed:
say $r;
}
There is also the non-blocking L<method poll|/type/Channel#method_poll>
which returns an available item from the channel or L<Nil> if there
is no item or the channel is closed, this does of course mean that the
channel must be checked to determine whether it is closed:
my $c = Channel.new;
start {
my $closed = $c.closed;
loop {
if $c.poll -> $item {
say $item;
}
elsif $closed {
last;
}
}
}
await (^10).map: -> $r {
start {
sleep $r;
$c.send($r);
}
}
$c.close;
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.
=head1 Low-level APIs
=head2 Threads
Expand Down

0 comments on commit 1d73e2a

Please sign in to comment.