Skip to content

Commit

Permalink
Merge pull request #3320 from joshkel/strategy-unhandled-rejection
Browse files Browse the repository at this point in the history
Strategy unhandled rejection
  • Loading branch information
westonruter authored Dec 11, 2024
2 parents c77dceb + acd9391 commit 9c73193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/workbox-strategies/src/StrategyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<void> {
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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"composite": true,
"declaration": true,
"lib": ["es2017", "webworker"],
"lib": ["es2020", "webworker"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
Expand Down

0 comments on commit 9c73193

Please sign in to comment.