personal web client for Bluesky
typescript
solidjs
bluesky
atcute
1diff --git a/PrecacheController.js b/PrecacheController.js
2index e00975e3762dc6382c39bebee04a89a651aae3d0..5d830222ffbd8e5ed841bbf3fe2560d354ca87ca 100644
3--- a/PrecacheController.js
4+++ b/PrecacheController.js
5@@ -150,9 +150,7 @@ class PrecacheController {
6 return waitUntil(event, async () => {
7 const installReportPlugin = new PrecacheInstallReportPlugin();
8 this.strategy.plugins.push(installReportPlugin);
9- // Cache entries one at a time.
10- // See https://github.com/GoogleChrome/workbox/issues/2528
11- for (const [url, cacheKey] of this._urlsToCacheKeys) {
12+ await eachLimit(Array.from(this._urlsToCacheKeys), 6, async ([url, cacheKey]) => {
13 const integrity = this._cacheKeysToIntegrities.get(cacheKey);
14 const cacheMode = this._urlsToCacheModes.get(url);
15 const request = new Request(url, {
16@@ -165,7 +163,7 @@ class PrecacheController {
17 request,
18 event,
19 }));
20- }
21+ });
22 const { updatedURLs, notUpdatedURLs } = installReportPlugin;
23 if (process.env.NODE_ENV !== 'production') {
24 printInstallDetails(updatedURLs, notUpdatedURLs);
25@@ -290,3 +288,64 @@ class PrecacheController {
26 }
27 }
28 export { PrecacheController };
29+
30+const eachLimit = (values, limit, iterator) => {
31+ return new Promise((res, rej) => {
32+ let active = 0;
33+ let current = 0;
34+
35+ let fulfilled = false;
36+
37+ const resolve = () => {
38+ if (fulfilled || active > 0) {
39+ return;
40+ }
41+
42+ fulfilled = true;
43+ res();
44+ };
45+
46+ const reject = (err) => {
47+ if (fulfilled) {
48+ return;
49+ }
50+
51+ rej(err);
52+ };
53+
54+ const run = () => {
55+ const c = current++;
56+
57+ if (fulfilled) {
58+ return;
59+ }
60+ if (c >= values.length) {
61+ return resolve();
62+ }
63+
64+ const value = values[c];
65+
66+ active++;
67+
68+ try {
69+ const ret = iterator(value, c);
70+
71+ if (ret && 'then' in ret) {
72+ ret.then(() => {
73+ active--;
74+ run();
75+ }, rej);
76+ } else {
77+ active--;
78+ run();
79+ }
80+ } catch (err) {
81+ reject(err);
82+ }
83+ };
84+
85+ for (let i = 0; i < limit; i++) {
86+ run();
87+ }
88+ });
89+};