What is the when.js equivalent of Q.js's "done()"?

1.3k views Asked by At

In addition to then(), Q.js also has a done(). done() is usually called at the end of a promise chain, like this:

promise
.then(callback)
.then(callback)
.done(callback);

This will catch any rejections that were not handled by the previous then()s, and it will handle any exceptions raised in then()'s callbacks.

Is there something similar in when.js? How do you handle exceptions raised in callbacks? And what if you never register a rejection handler?

3

There are 3 answers

0
Binarytales On BEST ANSWER

It looks like when now has .done() as well as .catch() and .finally().

See https://github.com/cujojs/when/blob/master/docs/api.md#extended-promise-api

2
Mariusz Nowak On

There's no done in when.js.

I advice to request it in their issue tracker, and for a meantime use other library that provides done.

2
danielepolencic On

As far as I know, there is no done in when.js. Indeed, if you read the last paragraph dedicated to debugging, there is a mention on a tool called monitor, which:

[...] monitors promise state transitions and then takes action, such as logging to the console, when certain criteria are met, such as when a promise has been rejected but has no onRejected handlers attached to it, and thus the rejection would have been silent.