Make async for loops performant using Promise.all

This commit is contained in:
nimbleghost
2023-05-24 17:48:39 +02:00
parent c16da26780
commit 9056d68fc9
2 changed files with 37 additions and 39 deletions

View File

@@ -21,15 +21,16 @@ class Poller {
async pollAll() {
console.log(`[Poller] Polling all subscriptions`);
const subscriptions = await subscriptionManager.all();
for (const s of subscriptions) {
try {
// TODO(eslint): Switch to Promise.all
// eslint-disable-next-line no-await-in-loop
await this.poll(s);
} catch (e) {
console.log(`[Poller] Error polling ${s.id}`, e);
}
}
await Promise.all(
subscriptions.map(async (s) => {
try {
await this.poll(s);
} catch (e) {
console.log(`[Poller] Error polling ${s.id}`, e);
}
})
);
}
async poll(subscription) {