Re: [w3c/ServiceWorker] New "setup" lifecycle for service worker (#1576)

@hanguokai I think this pattern is more promise-like:

```js
const dataPromise = new Promise((resolve, reject) => {
  chrome.storage.sync.get(null, (data) => resolve(data));
});

// listen browser events, for example:
chrome.tabs.onUpdated.addListener(async (parameters) => {
  const data = await dataPromise;
});
```

This also means a given function is working with the same `data` throughout its execution. Whereas in your model, `Cache` could change half-way through a function, if `init()` is called by some other function.

-- 
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/1576#issuecomment-814704568

Received on Wednesday, 7 April 2021 08:13:30 UTC