deftjs / DeftJS

Extensions for Large-Scale Sencha Touch and Ext JS Applications
http://deftjs.org/
MIT License
285 stars 56 forks source link

Implement Promise::done() to rethrow Errors for unhandled rejections. #83

Closed johnyanarella closed 11 years ago

johnyanarella commented 11 years ago

One of the pitfalls of interacting with Promise-based APIs is the tendency for important errors to be silently swallowed unless an explicit rejection handler is specified.

For example:

var promise = doWork().then( function () {
  // logic in your callback throws an error and it is interpreted as a rejection.
  throw new Error('Boom!');
});

// The error is swallowed.

Q.js addresses this issue by introducing a done() method that terminates a chain of Promises, forcing subsequent rejections to be thrown as exceptions.

var promise = doWork().then( function () {
  // logic in your callback throws an error and it is interpreted as a rejection.
  throw new Error('Boom!');
}).done();

// The error is thrown on the next tick of the event loop.

The done() method ensures that unhandled rejections are rethrown.

johnyanarella commented 11 years ago

This feature and its associated unit tests have been implemented in the promises_aplus branch and will be part of the Deft JS 0.9 release.

johnyanarella commented 11 years ago

Deft.Promise::done() is now available as part of the new Promises/A+ compliant rewrite of Deft JS's Promises.

See also: #82