Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Promises / Exercises / Await many

Solution: Await many

Here is a possible solution to the task.

Code

my @jobs = (start { 2 }), (start { 3 }), (start { 4 });
say [*] await @jobs;

🦋 You can find the source code in the file await-many.raku.

Output

24

Comments

  1. The three promises run concurrently; await @jobs waits for all of them and returns their results in order, (2, 3, 4).

  2. The reduce metaoperator [*] multiplies them, giving 24.

Course navigation

Await many   |   Kept or broken