Course of Raku / Functional, concurrent, reactive, and web programming / Reactive programming / await / Exercises / Await a failure
Solution: Await a failure
Here is a possible solution to the task.
Code
my $p = start { die 'boom' };
try {
await $p;
CATCH {
default { say "caught: {.message}" }
}
}🦋 You can find the source code in the file await-two.raku.
Output
caught: boomComments
The promise’s block throws, so the promise is broken. The exception is not lost — it is held until someone awaits the promise.
await $prethrows it right there, where theCATCHphaser handles it like any ordinary exception. This is how errors in background work surface where you wait for the result.