Skip to content

Instantly share code, notes, and snippets.

@beaufortfrancois
Created October 10, 2017 08:34
Show Gist options
  • Save beaufortfrancois/db73a41bf62c7b4ff11d7c24c7b9e00e to your computer and use it in GitHub Desktop.
Save beaufortfrancois/db73a41bf62c7b4ff11d7c24c7b9e00e to your computer and use it in GitHub Desktop.
Promise.prototype.finally vs try/catch/finally with Async/Await
// 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