Skip to content

Instantly share code, notes, and snippets.

@talitaoliveira
Last active November 27, 2018 01:32
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 talitaoliveira/facedc1fd2dce7b3fb9dc6f310324e52 to your computer and use it in GitHub Desktop.
Save talitaoliveira/facedc1fd2dce7b3fb9dc6f310324e52 to your computer and use it in GitHub Desktop.
Using the new feature of ES9: promise.prototype.finally()
/**
* PROMISE.PROTOTYPE.FINALLY()
* - Always executed
* - Allow to execute some code if the promise is successful or not successful
* - Similar to finally {} on synchronous code (try/catch/finally)
*/
// example
fetch('https://randomuser.me/api/?results=1')
.then(data => data.json())
.then(jsonData => console.log(jsonData))
.catch(error => console.error(error))
.finally(() => console.log('finished'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment