-
-
Notifications
You must be signed in to change notification settings - Fork 168
Description
Shared Web Workers are a relatively new feature that allow multiple scripts communicate with a single worker. A good use case would be for example sharing computation between multiple browser tabs.
When it comes to browser support, the feature is well supported apart from Safari. It used to have the feature for a while but then it was dropped. The background for the decision is explained at https://bugs.webkit.org/show_bug.cgi?id=149850 .
As we would have a direct use case for the feature in our current project, would it be possible for you to consider inclusion of the feature to threads.js? I am happy to contribute the code if we can agree on the steps. I imagine we would have to expose SharedWorker
from threads.js itself and then also make sure the addition works with the webpack plugin. Safari might require some kind of a strategy as well.
Reference: GoogleChromeLabs/worker-plugin#42 (shared worker support in Google's worker-plugin)
Activity
andywer commentedon Oct 4, 2021
Hey @bebraw!
Sure, I had my eye on shared workers for years, but didn't really consider it as a priority. Makes perfect sense, though.
Regarding the steps… I think you pretty much wrapped it up already. Just to have an overview:
threads-plugin
SharedWorker
fromthreads
, so the threads-plugin can recognize itWorker
to make it work withts-node
If you can contribute something, I would be happy to review and release it 🙂
bebraw commentedon Oct 5, 2021
I set up #402 . It's good for an early look and I'll refine based on your feedback.
phal0r commentedon Aug 15, 2022
FYI: Safari added support again. I can already enable it on Mac with Safari 15.6 as an experimental feature.
852Kerfunkle commentedon Feb 2, 2023
Well, I gave it another go. See #458.
I'll admit, it's not as simple as one might have thought it would be. Not a complaint, I see why the code works like it does.
Thanks @bebraw for your attempt, I hopefully learned from it.
852Kerfunkle commentedon Feb 7, 2023
Well, see the pull request for some hints why adding SharedWorkers to threads.js is somewhat difficult.
But it was not for nothing. I made this in the meantime, only for WebWorkers (dedicated, shared, maybe also service). Similar to the threads.js api, but not quite the same. The pool is a little basic, but I'm sure it can be improved in the future:
https://github.com/852Kerfunkle/threads-es