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
This commit is contained in:
parent
ad3329a78b
commit
b953a0c5a5
|
@ -1037,9 +1037,7 @@ export class Driver implements Debuggable, UpdateSource {
|
||||||
|
|
||||||
const clients = await this.scope.clients.matchAll();
|
const clients = await this.scope.clients.matchAll();
|
||||||
|
|
||||||
await clients.reduce(async (previous, client) => {
|
await Promise.all(clients.map(async client => {
|
||||||
await previous;
|
|
||||||
|
|
||||||
// Firstly, determine which version this client is on.
|
// Firstly, determine which version this client is on.
|
||||||
const version = this.clientVersionMap.get(client.id);
|
const version = this.clientVersionMap.get(client.id);
|
||||||
if (version === undefined) {
|
if (version === undefined) {
|
||||||
|
@ -1062,7 +1060,7 @@ export class Driver implements Debuggable, UpdateSource {
|
||||||
};
|
};
|
||||||
|
|
||||||
client.postMessage(notice);
|
client.postMessage(notice);
|
||||||
}, Promise.resolve());
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async broadcast(msg: Object): Promise<void> {
|
async broadcast(msg: Object): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue