Make async for loops performant using Promise.all

This commit is contained in:
nimbleghost 2023-05-24 17:48:39 +02:00
parent d625a003b8
commit 1291c3afe9
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) {