ECMAScript Proposal, specs, and reference implementation for
Many promise libraries have a "finally" method, for registering a callback to be invoked when a promise is settled (either fulfilled, or rejected). The essential use case here is cleanup - I want to hide the "loading" spinner on my AJAX request, or I want to close any file handles I’ve opened, or I want to log that an operation has completed regardless of whether it succeeded or not.
promise.finally(func) is similar to
promise.then(func, func), but is different in a few critical ways:
... read the whole story at github.com.
- When creating a function inline, you can pass it once, instead of being forced to either declare it twice, or create a variable for it