- From: Jackie Han <notifications@github.com>
- Date: Tue, 06 Apr 2021 09:18:16 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Tuesday, 6 April 2021 16:18:29 UTC
My initial problem is that if multiple events come **at the same time**, `await readDataFromStorage()` will be called multiple times if I don't use my initial snippet in this post. Your solution, in that condition, the `init_promise` will be awaited multiple times. `await` a resolved promise is Ok, although not common. Use your method, my code will look like: ``` var cache; var init_promise = async function() { cache = await readDataFromStorage(); }(); chrome.tabs.onUpdated.addListener(function(parameters) { await init_promise(); // use cache data process events }); ``` Your solution is more simple than my initial solution. But if service worker support 'setup' phase, no need to use an init_promise, and everything's ready, that is more easy to understand. I think 'setup phase' like 'top level await' in service worker, they do the same thing. For example, the code can like below ``` var cache = await readDataFromStorage(); // then listen events ``` So 'setup phase' vs 'top level await', which is better? -- 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-814250533
Received on Tuesday, 6 April 2021 16:18:29 UTC