As I work on developing a single-page app, JavaScript promises have become a critical component. In specific scenarios, I require the "then" method to execute synchronously if the promise is already resolved. To address this need, I have created a custom promise implementation as a wrapper class, which serves its purpose effectively but hinders my ability to utilize async/await. Can both be used simultaneously considering async/await appears to be essentially just syntax sugar around "then?"
The custom promise implementation adheres to the PromiseLike
TypeScript interface, yet it seems that async/await always requires a native promise. Why is this so?
I'm contemplating the idea of replacing the "then" method of an authentic promise object rather than constructing a wrapper on top of it. Will this approach yield the desired outcome?
The urgency for immediate execution of "then" stems from the fact that the culmination of the promise chain signifies a property within a React component. This React component exhibits a loading indicator until the promise resolves. Without my custom wrapper, the loading indicator flickers each time the component updates, disrupting user interaction.
Perhaps there exists an alternative solution to tackle this issue. This venture into the realm of JavaScript marks my maiden voyage.
In my development endeavors, I employ TypeScript and target ES6 standards.