Takes an array of tasks and returns a promise that resolves or rejects as soon as the first task settles.
Cancellable configuration options.
The tasks to execute.
A cancellable handle that resolves or rejects with the first settled task's result or error.
const handle = race( {}, async (token) => { await token.sleep(50); return "slow"; }, async (token) => { await token.sleep(10); return "fast"; },);const winner = await handle; // "fast" Copy
const handle = race( {}, async (token) => { await token.sleep(50); return "slow"; }, async (token) => { await token.sleep(10); return "fast"; },);const winner = await handle; // "fast"
Takes an array of tasks and returns a promise that resolves or rejects as soon as the first task settles.