Re: [w3c/ServiceWorker] Consider throwing when non-promise is passed to `waitUntil`. (#1068)

I think a couple of helper functions would be useful here. Something like:

```js
addWaitingListener('install', async event => {
  const cache = await caches.open('stuff');
  await cache.addAll(urls);
});
```

Which adds the function as a listener for the event, but also passes the returned value to `waitUntil`.

We could also have:

```js
addFetchListener(async (event, respond) => {
  const response = await fetch(event.request);
  const responseClone = response.clone();
  respond(response);
  
  const cache = await caches.open('stuff');
  await cache.put(event.request, responseClone);
});
```

The above would have to call `respondWith` synchronously and wait for `respond` to be called. If it doesn't get a response it can respond with `fetch(event.request)`. Meanwhile the returned promise is passed to `waitUntil`.

We could create these as little libraries, or get them into https://github.com/GoogleChrome/sw-toolbox

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1068#issuecomment-278368743

Received on Wednesday, 8 February 2017 15:57:32 UTC