Promise.withResolvers()

Creates a promise together with its resolve and reject functions.

Since ES2024 Spec ↗

Syntax

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

Returns

object — An object with `promise`, `resolve`, and `reject` properties.

Examples

const { promise, resolve } = Promise.withResolvers();
resolve("done");
promise.then(v => console.log(v));
Output
done
const { promise, reject } = Promise.withResolvers();
reject(new Error("failed"));
promise.catch(e => console.log(e.message));
Output
failed

Notes

- Avoids the "promise constructor" closure pattern by exposing the resolvers directly. - Handy for adapting event-based or callback-based APIs to promises.

Browser & runtime support

EnvironmentSince version
chrome 119
firefox 121
safari 17.4
edge 119
node 22.0

See also