Promises
In the previous section, we were creating some code blocks that were running in parallel. Promises help to see the status of the completeness of such blocks. In Perl 6, promises are handled by the Promise
class.
Creating a promise
To create a promise, just call the constructor of the Promise
class:
my $promise = Promise.new();
The created object does nothing yet. In the Factory methods section later in this chapter, we will see how to create a promise that executes some code. Meanwhile, let's see the properties that a promise has.
Statuses of a promise
The power of promises is that they can be either kept or broken, and you can keep track of them. A new promise that is created by calling Promise.new
is neither kept nor broken. Its status is Planned
. To see the status, call the status
method:
my $promise = Promise.new(); say $promise.status(); # Planned
The Promise
class also provides us with a pair of methods, keep
and break
, which change the status of a promise to Kept
or Broken
. This...