Creates a new Promise, returning the promise along with its resolve and reject functions.
const { promise, resolve, reject } = promiseWithResolvers();setTimeout(() => { resolve();}, 1000);await promise; Copy
const { promise, resolve, reject } = promiseWithResolvers();setTimeout(() => { resolve();}, 1000);await promise;
Promise would be passed somewhere that expects a promise, and you're free to call resolve or reject when needed.
resolve
reject
Creates a new Promise, returning the promise along with its resolve and reject functions.
Promise would be passed somewhere that expects a promise, and you're free to call
resolve
orreject
when needed.