Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / await / Exercises / Await a supply

Solution: Await a supply

Here is a possible solution to the task.

Code

my @values;

react {
    whenever Supply.from-list('a', 'b', 'c') {
        @values.push($_);
    }
}

say @values.join('-');

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

Output

a-b-c

Comments

  1. The react block waits until the supply is done, so @values holds all three strings, in order, afterwards.

  2. .join('-') glues them with dashes, giving a-b-c. The react block gave us the same “wait until complete” guarantee that await gives for a promise.

Course navigation

Await a supply   |   Await a failure