Make async for loops performant using Promise.all
This commit is contained in:
parent
d625a003b8
commit
1291c3afe9
2 changed files with 37 additions and 39 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue