Open this example in the interactive library
Source code
const { promise, resolve } = Promise.withResolvers();
queueMicrotask(() => resolve("ready"));
console.log(await promise);
Sample output
ready

Resolve a promise through an external callback in JavaScript.
Open this example in the interactive library
const { promise, resolve } = Promise.withResolvers();
queueMicrotask(() => resolve("ready"));
console.log(await promise);
ready