Promises

Promise.withResolvers()

ECMAScript API used in Node.js: creates a promise together with the functions that resolve or reject it. It is useful for adapting a controlled callback or test signal. Each promise settles only once; do not keep unresolved promises around without a failure or cancellation strategy. Tested on Node.js 22.16.0. Example output (one line per entry): ["ready", "ready"].

Formal Syntax & Structure

nodejs syntaxnodejs
Promise.withResolvers()

Return Value

object

Contains promise, resolve and reject.

Working Example

Example Snippetnodejs
const { promise, resolve, reject } = Promise.withResolvers();setImmediate(() => resolve('ready'));console.log(await promise);reject(new Error('too late'));console.log(await promise);
Node.js Reference