πŸ“˜ The closed method in Perl 6 channels

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s