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 $sensor = Supply.from-list(18, 21, 19, 23);
my $last = await $sensor;
say "final reading: $last";🦋 You can find the source code in the file await-a-supply.raku.
Output
final reading: 23Comments
Awaiting a supply blocks until the stream has emitted everything it has — the same “wait until complete” that
awaitgives for a promise — and its value is the last thing the supply emitted,23.This suits a stream where only the end state matters, like the latest sensor reading. If you need every value, that is a job for
.tapor areactblock, as in the previous sections.