I've read of promises for maps but I can't seem to know how to implement it if the map is inside a function.
for Example:
async function1(){
await mongoose.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const account = await Account.find({
priority: { $lt: 50000 },
}).skip(i * 1000).limit(1000).sort("priority");
const promise1 = await account.map(async (item) => {
//make axios requests here
}
Promise.allSettled(promise1).then(()=> process.exit(0))
}
However, I have this code wherein the map is inside a for loop.
async function1(){
await mongoose.connect(CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
//axios requests
for (let i=0; i<50; i++){
const account = await Account.find({
priority: { $lt: 50000 },
})
.skip(i * 1000)
.limit(1000)
.sort("priority");
await account.map(async (item) => {
//make axios requests here
}
}
//should wait for the map inside the loop to finish before executing
process.exit(0)
}