Created
October 10, 2017 08:34
-
-
Save beaufortfrancois/db73a41bf62c7b4ff11d7c24c7b9e00e to your computer and use it in GitHub Desktop.
Promise.prototype.finally vs try/catch/finally with Async/Await
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 | |
fetch('http://foo.bar') | |
.then(response => console.log(response)) | |
.catch(error => console.log(error)) | |
.finally(_ => console.log('finally')) | |
// try/catch/finally with Async/Await | |
try { | |
console.log(await fetch('http://foo.bar')); | |
} catch(error) { | |
console.log(error); | |
} finally { | |
console.log('finally'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment