Difference between done() and then()

89 views
Skip to first unread message

Jonas Amundsen

unread,
Apr 15, 2015, 5:30:43 PM4/15/15
to q-con...@googlegroups.com
Hi

Is there any difference between using then() and ending the promise chain with done() as opposed to just using done()? I have illustrated the two ways below, for clarity.

foo().then(function (resolution) {
  // ...
}).done();

foo().done(function (resolution) {
  // ...
});

Stuart Knightley

unread,
Apr 16, 2015, 1:51:48 PM4/16/15
to q-con...@googlegroups.com
Nope, there's no difference between the two.

In the past I have lent towards keeping the handlers in `.then(...)` and ending with just `.done()`

--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mariusz Nowak

unread,
Apr 17, 2015, 12:01:08 PM4/17/15
to q-con...@googlegroups.com
You can refer to it as to map and forEach in case of arrays.

If you just want to iterate an array, will you use forEach or map? Of course both will work, and you can be ok with map in all cases. but as you know it produces another array, so probably cleaner is to stay with forEach.
Same is with then. In contrary to done, it produces another promise, if you don't needed it, it's cleaner to just use done.

There are also other important implication that comes with then, that is error swallowing (try to crash in callback). If library you're using is not backed with proper error reporting mechanism, then you'll be left with silent exceptions, and trust me, it's last thing you want to deal with.
Reply all
Reply to author
Forward
0 new messages