Skip to content

Instantly share code, notes, and snippets.

@ronaldsmartin
Created April 9, 2020 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronaldsmartin/ccf6577258f81dfcab8da259649be96b to your computer and use it in GitHub Desktop.
Save ronaldsmartin/ccf6577258f81dfcab8da259649be96b to your computer and use it in GitHub Desktop.
Promise.all does not rethrow errors
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]
@ronaldsmartin
Copy link
Author

This was wrong! Has weird results because of Array(4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment