diff --git a/packages/workbox-strategies/src/StrategyHandler.ts b/packages/workbox-strategies/src/StrategyHandler.ts index 88609255a..56c60bcae 100644 --- a/packages/workbox-strategies/src/StrategyHandler.ts +++ b/packages/workbox-strategies/src/StrategyHandler.ts @@ -29,7 +29,7 @@ function toRequest(input: RequestInfo) { } /** - * A class created every time a Strategy instance instance calls + * A class created every time a Strategy instance calls * {@link workbox-strategies.Strategy~handle} or * {@link workbox-strategies.Strategy~handleAll} that wraps all fetch and * cache actions around plugin callbacks and keeps track of when the strategy @@ -534,7 +534,7 @@ class StrategyHandler { /** * Adds a promise to the * [extend lifetime promises]{@link https://w3c.github.io/ServiceWorker/#extendableevent-extend-lifetime-promises} - * of the event event associated with the request being handled (usually a + * of the event associated with the request being handled (usually a * `FetchEvent`). * * Note: you can await @@ -556,13 +556,17 @@ class StrategyHandler { * * Note: any work done after `doneWaiting()` settles should be manually * passed to an event's `waitUntil()` method (not this handler's - * `waitUntil()` method), otherwise the service worker thread my be killed + * `waitUntil()` method), otherwise the service worker thread may be killed * prior to your work completing. */ async doneWaiting(): Promise { - let promise; - while ((promise = this._extendLifetimePromises.shift())) { - await promise; + while (this._extendLifetimePromises.length) { + const promises = this._extendLifetimePromises.splice(0); + const result = await Promise.allSettled(promises); + const firstRejection = result.find((i) => i.status === 'rejected'); + if (firstRejection) { + throw (firstRejection as PromiseRejectedResult).reason; + } } } diff --git a/tsconfig.json b/tsconfig.json index 9ca662e37..37bf717ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "composite": true, "declaration": true, - "lib": ["es2017", "webworker"], + "lib": ["es2020", "webworker"], "module": "esnext", "moduleResolution": "node", "noFallthroughCasesInSwitch": true,