Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Streamline Channel.iterator, fixes RT #131684
- move logic of receive-nil-on-close into .iterator.pull-one
- remove receive-nil-on-close altogether
  • Loading branch information
lizmat committed Mar 22, 2018
1 parent f4255d5 commit bdd8143
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions src/core/Channel.pm6
Expand Up @@ -69,25 +69,6 @@ my class Channel does Awaitable {
)
)
}
method receive-nil-on-close(Channel:D:) {
nqp::if(
nqp::istype((my \msg := nqp::shift($!queue)),CHANNEL_CLOSE),
nqp::stmts(
nqp::push($!queue, msg), # make sure other readers see it
$!closed_promise_vow.keep(Nil),
Nil
),
nqp::if(
nqp::istype(msg,CHANNEL_FAIL),
nqp::stmts(
nqp::push($!queue,msg), # make sure other readers see it
$!closed_promise_vow.break(my $error := msg.error),
$error.rethrow
),
msg
)
)
}

method poll(Channel:D:) {
nqp::if(
Expand Down Expand Up @@ -169,14 +150,30 @@ my class Channel does Awaitable {

method iterator(Channel:D:) {
class :: does Iterator {
has $!channel;
method !SET-SELF($!channel) { self }
method new(\c) { nqp::create(self)!SET-SELF(c) }
has $!queue;
has $!vow;
method new(\queue,\vow) { nqp::create(self).SET-SELF(queue,vow) }
method SET-SELF(\queue,\vow) { $!queue := queue; $!vow := vow; self }
method pull-one() {
my Mu \got = $!channel.receive-nil-on-close;
nqp::eqaddr(got, Nil) ?? IterationEnd !! got
nqp::if(
nqp::istype((my \msg := nqp::shift($!queue)),CHANNEL_CLOSE),
nqp::stmts(
nqp::push($!queue,msg), # make sure other readers see it
$!vow.keep(Nil),
IterationEnd
),
nqp::if(
nqp::istype(msg,CHANNEL_FAIL),
nqp::stmts(
nqp::push($!queue,msg), # make sure other readers see it
$!vow.break(my $error := msg.error),
$error.rethrow
),
msg
)
)
}
}.new(self)
}.new($!queue,$!closed_promise_vow)
}

method list(Channel:D:) { self.Seq.list }
Expand Down

0 comments on commit bdd8143

Please sign in to comment.