I am trying to execute multiple promises using async with map:
const testAsyncFunction = async function testAsyncFunction() {
const array = ["var1", "var2"];
const promises = array.map(
(variable) =>
async function () {
// This doesn't get logged
console.log(
" ~ file: coursesServices.js ~ line 853 ~ testAsyncFunction ~ variable",
variable
);
return variable + "TEST";
}
);
const promises_results = await Promise.all(promises);
// This gets logged
console.log(
" ~ file: coursesServices.js ~ line 861 ~ testAsyncFunction ~ promises_results",
promises_results
);
};
testAsyncFunction();
The problem here is that the code inside the map function never gets executed.
This is what gets logged in the console:
~ file: coursesServices.js ~ line 861 ~ testAsyncFunction ~ promises_results [ [AsyncFunction (anonymous)], [AsyncFunction (anonymous)] ]
I don't see what I'm doing wrong exactly. But, I have a feeling that Promise.all wouldn't work on an array of async functions.