Propagation in Q

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 fulfilled
  • If an exception is thrown in a handler, reapPromise will get rejected
  • If ...

Get Mastering JavaScript Promises now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.