Promises

Promise.race()

ECMAScript API used in Node.js: settles with the first input to settle, whether fulfilled or rejected. A race does not cancel the remaining work, so use an AbortSignal and explicit cleanup for a real operation deadline. An empty iterable never settles. Tested on Node.js 22.16.0. Example output (one line per entry): ["cached", "later"].

Formal Syntax & Structure

nodejs syntaxnodejs
Promise.race(iterable)

Parameters & Attributes

NameTypeDescription
iterableIterableInputs to race.

Return Value

Promise

First settled outcome.

Working Example

Example Snippetnodejs
const pending = Promise.withResolvers();const result = await Promise.race([pending.promise, Promise.resolve('cached')]);console.log(result);pending.resolve('later');console.log(await pending.promise);
Node.js Reference