September 2017
Beginner
402 pages
9h 52m
English
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 is demonstrated in the following example, where one of the promises is marked as kept while the second is forced to be broken:
my $promise1 = Promise.new();my $promise2 = Promise.new();$promise1.keep();$promise2.break();say $promise1.status();say $promise2.status();
The output is:
Read now
Unlock full access