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.
Search the reference...
/
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!"
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →