Skip to content

Support for Shared Web Workers #401

@bebraw

Description

@bebraw

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

andywer commented on Oct 4, 2021

@andywer
Owner

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 🙂

linked a pull request that will close this issue on Oct 5, 2021
bebraw

bebraw commented on Oct 5, 2021

@bebraw
Author

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

phal0r

phal0r commented on Aug 15, 2022

@phal0r

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

852Kerfunkle

852Kerfunkle commented on Feb 2, 2023

@852Kerfunkle
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.

linked a pull request that will close this issue on Feb 2, 2023
852Kerfunkle

852Kerfunkle commented on Feb 7, 2023

@852Kerfunkle
Contributor

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @bebraw@andywer@phal0r@852Kerfunkle

      Issue actions

        Support for Shared Web Workers · Issue #401 · andywer/threads.js