Last active
February 1, 2018 20:55
-
-
Save alexburner/cfe1446e075c87b50e3fe4ebe48c86db to your computer and use it in GitHub Desktop.
.then() can be used as a .finally() if chained after a .catch()
This file contains hidden or 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
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