JavaScript Promise.withResolvers() Method
The Promise.withResolvers() static method creates a new promise and returns it together with its resolve and reject functions, so it can be settled from outside.
Description
The Promise.withResolvers() static method returns a new promise along with the resolve and reject functions that control it. It replaces the pattern of creating a promise and copying those functions out of the executor into outer variables, which is common when wrapping event-based APIs.
Typical uses include turning a one-off event into a promise, such as waiting for a dialog to close, building queues where a task's promise is fulfilled later by a worker, and testing code that waits for promises. The returned functions can be called from anywhere, as many times as you like, but only the first call has any effect.
Before this method existed, the same result needed a few lines of boilerplate: declaring resolve and reject variables and assigning them inside new Promise((res, rej) => { ... }).
Syntax
Promise.withResolvers()Return Value
An object with promise, resolve and reject properties.
Example
Browser Support
The following information will show you the current browser support for the Promise.withResolvers() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





