πŸ“˜ The closed method in Perl 6 channels

πŸ“˜ The closed method in Raku channels

N. B. Perl 6 has been renamed to Raku. Click to read more.


The Channel class also defines a method that checks on whether the channel is closed. This method is called closed.

my $c = Channel.new;
say "open" if !$c.closed; # is openΒ 

$c.close;
say "closed" if $c.closed; # closed

Despite the simplicity of using the method, it in fact returns not a simple Boolean value but a promise object (a variable of the Promise class). A promise (we will talk about this later) can be either kept or broken. Thus, if the channel is open, the closed promise is not yet kept; it is only given (or planned).

Promise.new(status => PromiseStatus::Planned, …) 

After the channel is closed, the promise is kept.

Promise.new(status => PromiseStatus::Kept, …) 

You can see the state of the promise above in its status field.

Leave a Reply

Your email address will not be published. Required fields are marked *