I'm perplexed why a previous engineer wrote some code that looks like double work to me. Could you not just do either the accounts.map()
or the for (const acct of accounts)
? Why both?
const accounts = await mongohelper.find(conn, 'accounts', query, 2000);
if(!accounts.length){return;}
const arrayofwork = accounts.map(act => salesmanwork(act, conn))
for (const act of accounts) {
arrayofwork.push(salesmanwork(act, conn));
}
await Promise.allSettled(arrayofwork)
return await recursivecall(workitemin, count);