September 2017
Beginner
402 pages
9h 52m
English
The Promise class has the then method, which can be used to bind the code that will be executed after the promise is kept or broken. In fact, this method creates and returns a new promise, which will be run after the initial promise status change:
my $promise = Promise.in(1);my $next = $promise.then({ say 'Done';});await $next;
This program prints Done 1 second after it starts. The first promise, saved in the $promise variable, is kept after a given time delay. Then, the then creates another promise, which is saved in the $next variable. To join to the main program, it is necessary to wait until $next prints the output and is thus completed.
Read now
Unlock full access