Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Promise.withResolvers() creates a promise with exposed resolve and reject functions! No more wrapping logic in the Promise constructor - you get the promise, resolve, and reject all separately!
Old vs new way of creating controllable promises
Practical scenarios for Promise.withResolvers
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
// Use promise, resolve, rejectAwkward variable hoisting pattern
const { promise, resolve, reject } =
Promise.withResolvers();
// Use promise, resolve, rejectClean, explicit destructuring
Returns promise, resolve, and reject
Resolve/reject from outside executor
No more variable hoisting tricks
Flexible promise creation