Created
December 9, 2016 21:43
-
-
Save tkissing/ab5b2817cc1c3820f569223e5ad58b0b to your computer and use it in GitHub Desktop.
Using throw inside new Promise()
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
new Promise((resolve, reject) => { | |
resolve(someArr.map(e => { | |
if (e.foo) { | |
reject(Error('Found a foo!')); | |
// the .map will continue to loop | |
// even resolve will still be called although it won't have any more effect | |
} | |
return e.bar; | |
})); | |
}); |
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
new Promise(resolve => { | |
resolve(someArr.map(e => { | |
if (e.foo) { | |
throw Error('Found a foo!'); | |
// .map is aborted, resolve is never actually called, the promise is rejected immediately | |
} | |
return e.bar; | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment