Last active
November 27, 2018 01:32
-
-
Save talitaoliveira/facedc1fd2dce7b3fb9dc6f310324e52 to your computer and use it in GitHub Desktop.
Using the new feature of ES9: promise.prototype.finally()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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