Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Shared Web Workers #401

Open
bebraw opened this issue Oct 4, 2021 · 5 comments · May be fixed by #402 or #458
Open

Support for Shared Web Workers #401

bebraw opened this issue Oct 4, 2021 · 5 comments · May be fixed by #402 or #458

Comments

@bebraw
Copy link

bebraw commented Oct 4, 2021

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)

@andywer
Copy link
Owner

andywer commented 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:

  • Update threads-plugin
  • Export SharedWorker from threads, so the threads-plugin can recognize it
  • Likely requires small hacks similar to the exported normal Worker to make it work with ts-node

If you can contribute something, I would be happy to review and release it 🙂

@bebraw bebraw linked a pull request Oct 5, 2021 that will close this issue
@bebraw
Copy link
Author

bebraw commented Oct 5, 2021

I set up #402 . It's good for an early look and I'll refine based on your feedback.

@phal0r
Copy link

phal0r commented Aug 15, 2022

FYI: Safari added support again. I can already enable it on Mac with Safari 15.6 as an experimental feature.

@852Kerfunkle
Copy link
Contributor

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 852Kerfunkle linked a pull request Feb 2, 2023 that will close this issue
@852Kerfunkle
Copy link
Contributor

852Kerfunkle commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants