What is promise, promise.all and promise.race? How do you chain promises?
A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved (e.g., a network error occurred).
A promise is an object which can be returned synchronously from an asynchronous function. It will be in one of 3 possible states:
Once settled, a promise can not be resettled. Calling
Promises following the spec must follow a specific set of rules:
A promise is an object which can be returned synchronously from an asynchronous function. It will be in one of 3 possible states:
- Fulfilled:
onFulfilled()
will be called (e.g.,resolve()
was called)
- Rejected:
onRejected()
will be called (e.g.,reject()
was called)
- Pending: not yet fulfilled or rejected
Once settled, a promise can not be resettled. Calling
resolve()
or reject()
again will have no effect. The immutability of a settled promise is an important feature.Promises following the spec must follow a specific set of rules:
- A promise or “thenable” is an object that supplies a standard-compliant
.then()
method.
- A pending promise may transition into a fulfilled or rejected state.
- A fulfilled or rejected promise is settled, and must not transition into any other state.
- Once a promise is settled, it must have a value (which may be
undefined
). That value must not change.
Comments
Post a Comment