Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@spiralx
Created July 29, 2016 07:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spiralx/58675999ca5b28453538d30859761947 to your computer and use it in GitHub Desktop.
Save spiralx/58675999ca5b28453538d30859761947 to your computer and use it in GitHub Desktop.
Polyfill to add a finally() method to the Promise object
Promise.prototype.finally = function (callback) {
return this.then(
value => this.constructor.resolve(callback()).then(() => value),
reason => this.constructor.resolve(callback()).then(() => { throw reason })
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment