There is quite some topics posted about how async/await behaves in javascript map function, but still, detail explanation in bellow two examples would be nice:
const resultsPromises = myArray.map(async number => {
return await getResult(number);
});
const resultsPromises = myArray.map(number => {
return getResult(number);
});
edited: this if of course a fictional case, so just opened for debate, why,how and when should map function wait for await keyword. solutions how to modify this example, calling Promise.all() is kind of not the aim of this question.getResult is an async function
Promise.all. - zero298asyncfunction always returns aPromise, so all that's happening is that it's waiting forgetResult()to be resolved, and then passing that as the value of a newPromise. - Alnitak.mapwill not wait for the internalawaitto complete, so the effect is that they will all run in parallel. - Alnitak