Whats the difference between Q Promise library's .finally() and .done()?

What is the difference between using the Nodejs Q promise library's .finally() and .done() statements.

For example whats the difference between these two?

Q(...)
.then(...)
.finally(); //or fin()

Q(..)
.then()
.done();

promise.done(onSuccess, onError) plain simply allows you to process resolved value. Additional benefit is that doesn't imply any error swallowing (as it's case with promise.then), it guarantees that any involved exception would be exposed. It also effectively ends chain and doesn't return any further promise.

promise.finally(fn) is for registering a task that must be done after given promise resolves (it doesn't matter whether promise succeds or fails). Usually you use it for some kind of cleanup operations e.g. imagine you setup a progress bar, that needs to be hidden after request is done (no matter if it was successful), then just do promise.finally(hideProgressBar). Additionally finally returns input promise, so you can return it for further processing.

The difference is in chaining and error handling, and error logging:

Q(...)
.then(...) 
.finally();

Here, if the then throws, the finally will still run, but no error will log. In Q finally is run regardless of the .then being successful or not. This is like the finally keyword in JS try/catch/finally. It is also possible to chain additional thens to the chain in this case.

Q(..)
.then()
.done();

Here, done indicates that the promise chain has ended, you can not chain to it any more. If you pass it only an onFulfilled handler it will not run if the then threw, and it will log errors if it ends with an exception.