-
Notifications
You must be signed in to change notification settings - Fork 391
Description
Currently, when.js's promise provides .then(), so if you want to register the same callback to run whether the promise is resolved or rejected, you have to pass it explicitly as both the callback and errback to when() or .then(). Both jQuery Deferred, and Q's promises provide convenience methods for this.
Here's how you have to do it with when.js currently:
promise.then(callback, callback);
// or
when(promise, callback, callback);That's not horrible, but this seems like a nice convenience:
promise.always(callback);
// or
when.always(promise, callback);It might be interesting to provide both promise.always(callback) and when.always(promise, callback) so that when.always() can be used with other promise implementations. Also, since something like promise.always() is not part of the Promises/A spec, relying on it would mean tying your code to when.js's promise implementation. Using when.always(promise) is a bit more decoupled.
Seems like this also opens the door for a method that registers only a rejection handler. For example, to do that now:
promise.then(null, errback);
// or
when(promise, null, errback);Which is kind of ugly, and might cause a "WTF". So, could provide something like:
promise.rejected(errback);
// or
when.rejected(promise, errback);This seems like a much more limited use case to me, though.