Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / react and whenever / The react block
Quiz — react
What does the following program print?
my @got;
react {
whenever Supply.from-list(1, 2, 3, 4, 5) {
@got.push($_);
done if $_ == 3;
}
}
say @got;| 1 | [1 2 3] |
| 0 | [1 2 3 4 5] |
| 0 | [3] |
| 0 | [4 5] |
The whenever body collects each value, but calls
done as soon as it sees 3. done
closes the react block, so the supply is abandoned and
4 and 5 are never processed, leaving
[1 2 3].
Course navigation
← The react block | whenever →