Spawn and join tasks
spawn(future) starts cooperative work. join((a, b, ...)) starts every tuple child and returns results in source order, even when completion order differs. join_all does the same for a homogeneous array.
Failure or parent cancellation requests cancellation of unfinished siblings and drains their cleanup before the group settles.
async fn later(text: string, delay: int) -> string {
await sleep(delay)
text
}
async fn main() {
let results = await join((later("slow", 20), later("fast", 5)))
println("${results.0},${results.1}")
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: slow,fast
Ctrl/⌘+Enter runs the current lesson.