I have 2 functions with loops that I want to execute sequentially:
Function A executes
Within Function A there is a For loop triggering an external function
Once loop in Function A is finished doing its thing, then we start with Function B
I have tried with the following code but function B starts in parallel, doesn't wait for Function A to finish:
async function sendPosts() {
console.log("start send posts")
for (let post of posts) {
...
await channel.send({
...
}).then((message) => {
externalFunction(message);
})
.catch(err => console.log(err));
}
console.log("finish send posts")
}
async function sendComments() {
console.log("start send comments")
for (let comment of commentsData) {
...
}
console.log("finish send comments")
}
sendPosts().then(sendComments());