The then
method always returns a promise that will either be handled or rejected.
In our example code, we assign the output to the reapPromise
variable, which will hold the value:
var reapPromise = getInputPromise() .then(function (input) { }, function (reason) { });
The reapPromise
variable is the new promise for the return value of either handler. Only one handler will ever be called and it will be responsible for resolving reapPromise
as a function, which can only either return a value (a future value) or throw an exception.
Whatever is the case, there will be the following possible outcomes:
If you return a value in a handler,
reapPromise
will get fulfilledIf an exception is thrown in a handler,
reapPromise
will get rejectedIf a promise is returned in a handler,
reapPromise
will become that promiseAs it will become a new promise, it will be useful for managing delays, combining results, or recovering from errors.
If the getInputPromise()
promise gets rejected and you forget...