Create a deferred promise, with exposed resolve
and reject
methods which can be called separately.
This is useful when you want to return a Promise and have code outside the Promise resolve or reject it.
method
Create a deferred promise, with exposed resolve
and reject
methods which can be called separately.
This is useful when you want to return a Promise and have code outside the Promise resolve or reject it.
const { promise, resolve, reject } = Promise.withResolvers();
setTimeout(() => {
resolve("Hello world!");
}, 1000);
await promise; // "Hello world!"