First, tell us about the characteristics of promise:
1, once the state Promise of change can not be changed.
The compiler enter the code:
In the console print as follows:
Then enter in the compiler:
In the console print as follows:
You can see the status of the first and still the same success. Similarly, if the first execution of a reject then his status will not change.
to sum up:
2, then the desired parameter is a function of the method Promise, passing a non-penetration value function will occur.
.then we expect a transfer method, but you can not pass a method, when there are two .then, when you do not pass the first method, as it had happened, to penetrate the second .then . Similarly, if the second is not, then a method will always penetrate down.
3, Promise callback is synchronized, and then the callback is asynchronous.
It can be seen that the code is shaded portion promise are synchronized, and then the inside code is printed last asynchronous.
4, then calling chain, then a return value is received then the next parameter, if an error is returned, it will return a reject status of promise.
Then you can see the parameters of the second parameter is the first to get the return value. Then if it returns an error how to do it? Consider the following codes:
5, then the pullback in return a promise will enter a waiting state until the promise of changing the return.
then waits until the implementation of the method which changes state after promise after two seconds.