Aborting a promise

We saw how done(); is used earlier, but here it comes in with a total impression.

Using done();, we can conclude our promise and abort our program. I always have a way to chain the promises:

then().then().done();

If the promise is vetted (and did not catch the error before), the done() function forcibly spawns an uncatchable error (for example, setTimeout(function () {throw ex;}, 0)).

On Node.js REPL, run Q.reject("uncaught").done(), then exit with an error.

If the error reached to the done() function, you can think of it just a programming bug (not an exception state).

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.