Note await pauses execution inside an async function until the promise settles. Top-level await works in ES modules. Always handle errors with try/catch or .catch().
async awaitawait promiseasync functionasynchronous function
Note Runs all promises in parallel and resolves when ALL succeed. Rejects immediately if ANY promise rejects -- other pending promises are not cancelled, just ignored.
parallel promisesPromise.allconcurrent requestswait for all
Note Never rejects. Each result is { status: "fulfilled", value } or { status: "rejected", reason }. Use when you want all results regardless of failures.
Note Settles as soon as the first promise settles (fulfilled OR rejected). Common use: implementing timeouts.
promise racefirst to finishtimeout promisefastest promise
Promise.any()
syntax
Promise.any([p1, p2, p3])
example
asyncfunction fetchFromMirrors(path) {
return Promise.any([
fetch(`https://mirror1.example.com${path}`),
fetch(`https://mirror2.example.com${path}`),
fetch(`https://mirror3.example.com${path}`),
]);
}
// Returns the first successful response; ignores individual failures
Note Resolves with the first fulfilled promise. Only rejects if ALL promises reject (with an AggregateError). The opposite of Promise.race() for error handling.
Note Essential for cancelling stale requests (e.g., in search-as-you-type). The AbortSignal can be shared across multiple fetch calls to cancel them all at once.
Note Unhandled promise rejections crash Node.js and show warnings in browsers. Always catch async errors. The tuple pattern [data, error] is popular for cleaner control flow.