Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / react and whenever / whenever
Quiz — whenever
What does the following program print?
my @out;
react {
whenever Supply.from-list(1, 2, 3) {
@out.push($_ * 2);
}
}
say @out;| 0 | [1 2 3] |
| 1 | [2 4 6] |
| 0 | [6] |
| 0 | 12 |
The whenever body runs for each value, pushing twice its
value. The supply emits 1, 2, 3, so @out
collects 2, 4, 6.
Course navigation
← whenever | Collect with react →