0
I have a question, I need to make the code below, wait for the . map to be executed, and parseCategory() calls an API to get the articles. It turns out that the "final..." console output is executed before the . map.
Does anyone have a tip on what would be best practice?
async function parseCategories () {
var categories = ["business", "entertainment", "health", "sports", "technology"];
var articles = [];
await categories.map(category => {
parseCategory(category).then(result => {
articles.push(result);
console.log(category);
}).catch(error => {
logger.fail(error);
});
});
await console.log("final...");
}
a possible solution would be to use Promise, and Promise.all to run the precedents in parallel but show the ordered value
– Luan Brito