Ever wanted to be a “Promises whizz”. There are a few tricks you can learn to become that through the use of some promise static methods
On your way to become a “JavaScript Superstar” and “Promises whizz”, you’ll need to master the concept of handling multiple promises at the same time. There are some methods that are provided by the language to do just that, but before we dwell on those methods let’s begin with understanding some basics of “states” and “fates” of promises.
Promises generally have 3 possible mutually exclusive states, they are:
promise.then(f)
will call f
as soon as possiblepromise.then(undefined, r)
will call r
“as soon as possible.”An umbrella term, commonly used, for the above would be “settled” where a promise is said to be “settled” if it is not pending (that is if it is either fulfilled or rejected).
Promises have two possible mutually exclusive fates, they are:
Now that we have covered the concept of states and fates, we should now be able to understand promise concepts with common terminology. Let’s move on to the gist of the article.
#javascript #programming #developer