Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Promises / Exercises / Chain a promise
Solution: Chain a promise
Here is a possible solution to the task.
Code
my $p = start { 10 };
my $q = $p.then({ .result * 2 });
say await $q;🦋 You can find the source code in the file promise-result.raku.
Output
20Comments
.thenbuilds a new promise$qthat runs once$pis done. Inside the block,.resultis the value of the original promise,10.The follow-up doubles it, so awaiting
$qyields20. Chaining with.thenlets you build a pipeline where each step depends on the previous one’s result.
Course navigation
← Chain a promise | Await many →