- From: Jake Archibald <notifications@github.com>
- Date: Wed, 07 Apr 2021 01:13:17 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 7 April 2021 08:13:30 UTC
@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