Skip to content

Instantly share code, notes, and snippets.

@alexburner
Last active February 1, 2018 20:55
Show Gist options
  • Save alexburner/cfe1446e075c87b50e3fe4ebe48c86db to your computer and use it in GitHub Desktop.
Save alexburner/cfe1446e075c87b50e3fe4ebe48c86db to your computer and use it in GitHub Desktop.
.then() can be used as a .finally() if chained after a .catch()
new Promise((resolve, reject) => setTimeout(() => resolve('yay'), 100))
.then(val => console.log(val)) // yay
.catch(err => console.error(err)) // (never hit)
.then(() => console.log('finally 1'));
new Promise((resolve, reject) => setTimeout(() => reject('nay'), 200))
.then(val => console.log(val)) // (never hit)
.catch(err => console.error(err)) // nay
.then(() => console.log('finally 2'));
/*
Output:
> yay
> finally 1
> nay
> finally 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment