When the promise is resolved / rejected, it will call its error / error handler:
var promiseB = promiseA.then(function(result) {
The then method also returns a promise: promB, which will be allowed / rejected depending on the return value from the success / error handler from promA .
There are three possible values ββthat promise that success / error handlers are returned that will affect the outcome of the agreement:
1. Return nothing
Armed with this understanding, you can understand the following:
promiseB = promiseA.then(function(result) { return result + 1; });
Then the call returns promise B immediately. When declA is resolved, it will pass the result to promise a success handler. Since the return value is a promise of result + 1, the success handler returns a value (option 2 above), so promise B will be immediately resolved, and the promise of the success handler will be transmitted with the promise. Result + 1.
pixelbits Apr 08 '15 at 14:06 2015-04-08 14:06
source share