joinAll
joinAll espera a que cada JoinHandle<T> de un array se asiente, resolviéndose a sus resultados en el mismo orden en que se pasaron los handles.
Firma
joinAll<T>(handles: JoinHandle<T>[]): Promise<T[]>Se resuelve en cuanto cada handle ya se resolvió, sin importar cuál terminó primero de verdad, results[0] siempre es el resultado de handles[0], no el que se asentó más temprano. Se rechaza con el primer rechazo que observa, de la misma forma que Promise.all lo hace. Todo handle pasado a joinAll se consume igual que .join() consume uno, reutilizar un handle ya pasado a joinAll, a race, o a su propio .join(), se rechaza en tiempo de compilación (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]);
}