#Promise
States
A JavaScript Promise
can be in one of the following three mutually exclusive states:
fulfilled
: the operation completed successfully;rejected
: the operation did not complete successfully (typically due to an error);pending
: its future is still uncertain (i.e. it's neitherfulfilled
norrejected
).
A promise is said to be "settled" if it is not pending
(i.e. if it is either fulfilled
or rejected
).
Being "settled" does not constitute to a state, but is rather meant as a hypernym for fulfilled
and rejected
.
#Promise
Fates
A JavaScript Promise
has two possible mutually exclusive fates:
- resolved
- unresolved
A promise is considered resolved when:
- It has been either
fulfilled
orrejected
, or; - It has been "locked in" to follow another
Promise
— i.e. it was resolved with another pending promise and will now be waiting on the eventual state of it.
A promise is considered to be unresolved, simply when it has not resolved. An unresolved promise is always in the pending
state, while a resolved promise may be pending
(when "locked in" for example), fulfilled
or rejected
.
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.