Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Update async event.waitUntil example #10371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/site/content/en/learn/pwa/caching/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ self.addEventListener("install", event => {

The [`waitUntil()` method](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) receives a promise and asks the browser to wait for the task in the promise to resolve (fulfilled or failed) before terminating the service worker process. You may need to chain promises and return the `add()` or `addAll()` calls so that a single result gets to the `waitUntil()` method.

You can also handle promises using the async/await syntax. In that case, `waitUntil()` needs a promise-based function as an argument, so you need to create a function that returns the promise to make it work, as in the following example:
You can also handle promises using the async/await syntax. In that case, you need to create an asynchronous function that can call `await` and that returns a promise to `waitUntil()` after it's called, as in the following example:

```js/3
const urlsToCache = ["/", "app.js", "styles.css", "logo.svg"];
self.addEventListener("install", (event) => {
event.waitUntil(async () => {
event.waitUntil((async () => {
const cache = await caches.open("pwa-assets");
return cache.addAll(urlsToCache);
});
})());
});
```

Expand Down