From 31ed6c5d7e17bb2872abd6f4d661918542c0740e Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 28 Aug 2023 23:37:55 -0400 Subject: [PATCH] Update async event.waitUntil example --- src/site/content/en/learn/pwa/caching/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/site/content/en/learn/pwa/caching/index.md b/src/site/content/en/learn/pwa/caching/index.md index 5fa9f5b5fcc..65d75dcab13 100644 --- a/src/site/content/en/learn/pwa/caching/index.md +++ b/src/site/content/en/learn/pwa/caching/index.md @@ -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); - }); + })()); }); ```