deftjs / DeftJS

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

Rework Promise::always() to eliminate unintended side-effects. #84

Closed johnyanarella closed 11 years ago

johnyanarella commented 11 years ago

promise.always(fn) is akin to a finally in a try..catch..finally block (although it can occur anywhere a Promise chain).

Originally envisioned as a shorthand for promise.then(fn, fn), promise.always(fn) has a couple odd quirks:

The typical use case for promise.always() is to add handler logic that should be triggered regardless of whether the originating promise is fulfilled or rejected. In this scenario, the result or error parameter is ignored and the developer typically wouldn't think to inspect it and potentially rethrow it in the case of an Error.

Consequently, it makes sense for promise.always() to be changed to eliminate these quirks:

In the rare scenarios where the original behavior was actually desired, promise.then(fn, fn) can be used instead.

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

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

See also: #82