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

@wanderview I ended up making my app rely on global scope, so I'm hoping if multi-threading happens it'll be enabled via an option somehow.

> 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.

I could, but my app also auto-updates, and I want to avoid the situation where it does a big update twice, simply because two windows are open. Having SW manage all updates seems to work better in this case.

> You need to use the IDB transaction itself as the "lock". If the transaction does not complete it rolls back any changes.

I tried doing this but I couldn't get it to work, and it doesn't seem like IDB locks stay locked for very long. "Transactions are expected to be short-lived, so the browser can terminate a transaction that takes too long, in order to free up storage resources that the long-running transaction has locked." ([Mozilla](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Concepts_Behind_IndexedDB))

I ended up using promises to queue tasks, which requires global scope. Each new call to `do_blocking_task()` adds the passed task to the end of a queue of promises.

```
let CURRENT_TASK = Promise.resolve(null)
async function do_blocking_task(task){
    CURRENT_TASK = CURRENT_TASK.then(task)
}
```

-- 
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-290602394

Received on Friday, 31 March 2017 02:57:48 UTC