Skip to content

Instantly share code, notes, and snippets.

@juukie
Forked from spiralx/promise.finally.polyfill.js
Created February 27, 2019 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juukie/eabb7a6db9af908238f2b6f3359f53b6 to your computer and use it in GitHub Desktop.
Save juukie/eabb7a6db9af908238f2b6f3359f53b6 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