Promise
fullfill -> resolve, reject, eventual value/value. reason.

Promise represents the eventual completion of an async operation
It must be in one of these states
pending
initial state, not fulfilled or rejected
fulfilled
meaning that the operation completed successfully
rejected
meaning that the operation failed
It is guaranteed that a promise object will either succeed or fail
promise.all
returns a single promise that resolves when all of the promises in the argument have resolved or when the utterable argument contains no promises
create Promise example
Method:
Promise.all(iterable)Wait for all promises to be resolved, or for any to be rejected. If the returned promise resolves, it is resolved with an aggregating array of the values from the resolved promises in the same order as defined in the iterable of multiple promises.
Promise.race(iterable) Wait until any of the promises is resolved or rejected. If the returned promise resolves, it is resolved with the value of the first promise in the iterable that resolved. If it rejects, it is rejected with the reason from the first promise that was rejected.
Promise.resolve(value)Returns a new Promise object that is resolved with the given value.
Then() method
onFulfilled and two function()
onFulfilled(a, []) : call after promise finished. the a is the return of promise
onRejected(a, []) : call after promise finished. the a is the reason of promise
Then can be called multiply times:
if resolve: onFulfilled call back one by one
if reject: onRejected call back one by one
promise chain
Promise use observable module:

Implement promise all, resolve, reject, race
Promise all:
promises should be array of function
Race
Resolve
Reject
Then
Last updated
Was this helpful?