Created
April 9, 2020 18:48
-
-
Save ronaldsmartin/ccf6577258f81dfcab8da259649be96b to your computer and use it in GitHub Desktop.
Promise.all does not rethrow errors
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
export {}; | |
function f(): Promise<string> { | |
return new Promise<string>((resolve, reject) => { | |
reject("reject"); | |
}); | |
} | |
async function g() { | |
const results = await Promise.all( | |
Array(4).map(async _ => { | |
return await f(); | |
}) | |
); | |
console.log(results); | |
return results; | |
} | |
try { | |
g(); | |
console.log('No errors'); | |
} catch (e) { | |
console.log('Caught any error'); | |
} | |
// Prints: | |
// | |
// No errors | |
// > (4) [undefined, undefined, undefined, undefined] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was wrong! Has weird results because of
Array(4)
.