September 2017
Beginner
402 pages
9h 52m
English
In real programs, more than one promise can be used. Combining different promises can give very expressive ways of coding complex relationships between different parts of the code.
Let us start with a simple example and create three promises using the standalone start function:
say 'Start';await start {sleep 2; say 2;}, start {sleep 3; say 3;}, start {sleep 1; say 1;};say 'Done';
The goal is to pause the program until all the promises are kept. As you can see from this example, the await function accepts a list of promises and waits until all of them are completed. The output of the program looks like this:
Start123Done
Each promise creates a separate thread, which can be clearly seen by printing the $*THREAD variable: ...
Read now
Unlock full access