September 2017
Beginner
402 pages
9h 52m
English
Let us start with a simple program that creates a promise with a code block that prints something and exits. The Promise.start method creates a block and returns a promise. Notice that the returned value is a promise, not a thread. To wait until the code block of the promise is done, use the await function:
my $promise = Promise.start({ say 'I am a promise';});await $promise;
The program waits until the message is printed by the code block and exits:
I am a promise
In the preceding example, the start routine is called as a method of the Promise class. Alternatively, a promise can be created by a self-standing start function:
my $promise = start { say 'I am a promise';};await $promise;
Notice that there are no parentheses ...
Read now
Unlock full access