Skip to content

Commit

Permalink
Merge pull request #3471 from kbucheli/propberly_close_channel_supply
Browse files Browse the repository at this point in the history
properly close Channel Supply
  • Loading branch information
jnthn committed Feb 11, 2020
2 parents 774a839 + 6fbfc4a commit 8390016
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core.c/Channel.pm6
Expand Up @@ -119,8 +119,11 @@ my class Channel does Awaitable {
method Capture(Channel:D:) { self.List.Capture }
multi method Supply(Channel:D:) {
supply {
my $closed = False;

# Tap the async notification for new values supply.
whenever $!async-notify.unsanitized-supply.schedule-on($*SCHEDULER) {
done if $closed;
my Mu \got = self.poll;
if nqp::eqaddr(got, Nil) {
if $!closed_promise {
Expand Down Expand Up @@ -149,6 +152,7 @@ my class Channel does Awaitable {
# `last if ...` check in this loop is still essential.
my int $initial-items = nqp::elems($!queue);
while $initial-items-- {
done if $closed;
my Mu \got = self.poll;
last if nqp::eqaddr(got, Nil);
emit got;
Expand All @@ -159,6 +163,10 @@ my class Channel does Awaitable {
?? done()
!! X::AdHoc.new( payload => $!closed_promise.cause ).throw
}

CLOSE {
$closed = True;
}
}
}

Expand Down

0 comments on commit 8390016

Please sign in to comment.