Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Promise.withResolvers(): a promise with exposed resolving functions

Promise.withResolvers() returns a new promise and its associated resolve and reject functions. It separates creating a promise from supplying its outcome, for example when adapting a callback-based interface.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const { promise, resolve, reject } = Promise.withResolvers();

Promise.withResolvers() is a static method from ECMAScript 2024, not a Web API. It takes no arguments and returns an ordinary object with promise, resolve, and reject properties. With Promise.withResolvers(), the promise initially awaits an outcome; you do not supply an executor as in new Promise(executor).

resolve(value) accepts a value or adopts the eventual outcome of a promise or thenable. Calling resolve therefore does not always mean immediate fulfillment. reject(reason) rejects the promise. Only the first call to either function matters; later calls are ignored, even while an adopted outcome remains unknown.

Handlers registered with .then() run asynchronously. The example prints sync first, then fulfilled: 42; the reject call is ignored. Expose the resolving functions only to code that should control the outcome.

Check availability with typeof Promise.withResolvers === "function". The specification alone does not establish support in a particular browser; Node 24 in the repository does not establish it either.

Examples

const { promise, resolve, reject } = Promise.withResolvers();

promise.then(
  value => console.log(`fulfilled: ${value}`),
  reason => console.log(`rejected: ${reason}`)
);

resolve(42);
reject("ignored");
console.log("sync");

Result

sync
fulfilled: 42

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources