Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Include reference to Channel object in Channel-related errors
  • Loading branch information
moritz committed Dec 21, 2014
1 parent 4d9771f commit cc9f35a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/Channel.pm
@@ -1,9 +1,11 @@
# A channel provides a thread-safe way to send a series of values from some
# producer(s) to some consumer(s).
my class X::Channel::SendOnClosed is Exception {
has $.channel;
method message() { "Cannot send a message on a closed channel" }
}
my class X::Channel::ReceiveOnClosed is Exception {
has $.channel;
method message() { "Cannot receive a message on a closed channel" }
}
my class Channel {
Expand Down Expand Up @@ -32,15 +34,15 @@ my class Channel {
}

method send(Channel:D: \item) {
X::Channel::SendOnClosed.new.throw if $!closed;
X::Channel::SendOnClosed.new(channel => self).throw if $!closed;
nqp::push($!queue, nqp::decont(item));
}

method receive(Channel:D:) {
my \msg := nqp::shift($!queue);
if nqp::istype(msg, CHANNEL_CLOSE) {
$!closed_promise_vow.keep(Nil);
X::Channel::ReceiveOnClosed.new.throw
X::Channel::ReceiveOnClosed.new(channel => self).throw
}
elsif nqp::istype(msg, CHANNEL_FAIL) {
$!closed_promise_vow.break(msg.error);
Expand Down

0 comments on commit cc9f35a

Please sign in to comment.