Member-only story

A New Method for Promise, Is It Useful to You?

Streamlining Your Code: How the Innovative Promise.withResolvers Enhances Control and Simplifies Async Functions

Xiuer Old
3 min readFeb 23, 2024
A New Method for Promise
Designed with DALLE 3

Background 👨‍💻
Sometimes, we need to extract the resolve or reject parameters of a Promise for a specific purpose.

For Instance 🌟
In the example below, I want to manually control the timing of a Promise’s fulfillment. Hence, I need to take out the resolve and execute it when I think it’s appropriate, so the Promise becomes fulfilled.

However, this can be quite cumbersome as I always have to define an extra variable to store this resolve.

Promise.withResolvers New Method 💡
Promise has recently introduced a new method at the Stage 3 phase, which is Promise.withResolvers.

Its function is to deconstruct the resolve and reject of Promise instances for our use. In the earlier example, use Promise.withResolvers.

--

--

Xiuer Old
Xiuer Old

Written by Xiuer Old

🔥Little brother teaches front-end and AI online🌈

No responses yet