The final handler gets called, with no arguments, when the promise returned by getInputPromise() either returns a value or throws an error. The value returned or error thrown by getInputPromise() passes directly to outputPromise unless the final handler fails, and may be delayed if the final handler returns a promise.
var outputPromise = getInputPromise()
.fin(function () {
// close files, database connections, stop servers, conclude tests
});
If the handler returns a value, the value is ignored
If the handler throws an error, the error passes to outputPromise
If the handler returns a promise, outputPromise gets postponed. The
eventual value or error has the same effect as an immediate return
value or thrown error: a value would be ignored, an error would be
forwarded.
The error returned from
finally
-block should not be ignored.For example, Q's
finally
is described as: