0

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?

Matt Zukowski
  • 4,469
  • 4
  • 37
  • 38

3 Answers3

4

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

Binarytales
  • 9,468
  • 9
  • 32
  • 38
2

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.

danielepolencic
  • 4,905
  • 1
  • 26
  • 25
  • Alright thanks. I guess I could also use `.otherwise()` to catch stray rejections, but it's not clear from the documentation whether that would also catch any exceptions raised in previously bound callbacks. – Matt Zukowski Aug 21 '13 at 20:01
  • As far as I remember, rejections are passed down the chain of promises. So the answer is yes, it would catch exceptions raised previously. – danielepolencic Aug 21 '13 at 20:05
1

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.

Mariusz Nowak
  • 32,050
  • 5
  • 35
  • 37
  • In benchmarks, when.js [is a lot faster](https://github.com/cujojs/promise-perf-tests) than q.js, so losing `done()` might be worth it. Could you recommend another fast library that supports something like `done()`? – Matt Zukowski Aug 22 '13 at 13:37
  • 1
    I maintain [deferred](https://github.com/medikoo/deferred) you can check this one, it's fast and has `done` nearly from beginning. I my eyes `done` is a must have for a promise library. – Mariusz Nowak Aug 22 '13 at 14:55