From b953a0c5a5eb36c75bc644783c291486679dac3d Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 8 Jan 2021 13:59:34 +0200 Subject: [PATCH] refactor(service-worker): notify clients about updates in parallel (#40234) Previously, clients were notified about updates sequentially. This wasn't necessary. This commit changes the `Driver#notifyClientsAboutUpdate()` method to notify the clients in parallel (by switching from `Array#reduce()` to `Array#map()` and `Promise.all()`). This also aligns the `notifyClientsAboutUpdate()` method with the `notifyClientsAboutUnrecoverableState()` method. PR Close #40234 --- packages/service-worker/worker/src/driver.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index 30bc320f17..106d3a45ca 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -1037,9 +1037,7 @@ export class Driver implements Debuggable, UpdateSource { const clients = await this.scope.clients.matchAll(); - await clients.reduce(async (previous, client) => { - await previous; - + await Promise.all(clients.map(async client => { // Firstly, determine which version this client is on. const version = this.clientVersionMap.get(client.id); if (version === undefined) { @@ -1062,7 +1060,7 @@ export class Driver implements Debuggable, UpdateSource { }; client.postMessage(notice); - }, Promise.resolve()); + })); } async broadcast(msg: Object): Promise {