Re: [w3c/ServiceWorker] consider allowing multiple worker thread instances for a single registration (#756)

> My use case: App has multiple languages. Each can optionally be downloaded for offline use. Therefore, do not want to download all languages during SW install. App uses postMessage to tell SW when a new language should be added to the offline list. SW both downloads the new language and does a full update of all cached responses (in case API has changed and new language is using the new API).

I would recommend doing this in the window and not in the service worker.  You can download the new language pack and save it in cache all from the window.  Then you just switch the a "current cache name" value in your IDB atomically to get your fetch event handler to start using it.

> Where global variable comes in: I need a locking mechanism to prevent two updates happening at the same time. I could store a value in IDB, but what if that lock value is set to true and the update process fails without setting it back to false? Then no other update will happen as SW thinks one is still in progress. Instead, I plan to have a global UPDATE_IN_PROGRESS in SW, defaulting to false. Then, even if the update process dies, the value will reset to false when the SW is killed.

You need to use the IDB transaction itself as the "lock".  If the transaction does not complete it rolls back any changes.  Once you complete the transaction and commit the changes then other operations are unblocked.

-- 
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/756#issuecomment-243196278

Received on Monday, 29 August 2016 17:39:46 UTC