joinAll
joinAll waits for every JoinHandle<T> in an array to settle, resolving to their results in the same order the handles were given.
Signature
joinAll<T>(handles: JoinHandle<T>[]): Promise<T[]>It resolves once every handle has, regardless of which one actually finished first, results[0] is always handles[0]'s own result, not whichever settled earliest. It rejects with the first rejection it observes, the same way Promise.all does. Every handle passed to joinAll is consumed the same way .join() consumes one, so reusing a handle already passed to joinAll, or to race, or to its own .join(), is rejected at compile time (E3033).
tyrus
import { spawn, joinAll, sleepAsync } from "tyrus:task";
async function fetchShard(id: i32, delayMs: u64): Promise<i32> {
// Stands in for a real per-shard request; `sleepAsync` simulates each
// shard's own latency without needing real I/O for the example.
await sleepAsync(delayMs);
return id * 10;
}
async function main(): Promise<void> {
const shardA = spawn(async (): Promise<i32> => await fetchShard(1, 20));
const shardB = spawn(async (): Promise<i32> => await fetchShard(2, 10));
// `joinAll` waits for every shard and keeps the results in the same
// order the handles were given, regardless of which finishes first.
const shards: i32[] = await joinAll([shardA, shardB]);
print(shards[0] + shards[1]);
}