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

SharedWorker Support #78

Open
EstebanBorai opened this issue Oct 9, 2024 · 1 comment
Open

SharedWorker Support #78

EstebanBorai opened this issue Oct 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@EstebanBorai
Copy link

Motivations

Hi! I have been looking at this crate to implement a SharedWorker, I'm specifically looking for an approach that looks like this:

|-----------|    |-----------|
|  Window 1 |    |  Window 2 |
|           |    |           |
|           |    |           |
|-----------|    |-----------|
      |                |
      __________________
              |
        |-----------|
        |   Worker  |
        |           |
        |-----------|

But I don't seem to find references in docs nor code to SharedWorkers.

  • Would you like to implement this feature? [y/n]

Yes

Solution

Provide a SharedWorker implementation similar to

pub trait WebWorker: WebWorkerPath + Clone + 'static {
which extends: https://docs.rs/web-sys/latest/web_sys/struct.SharedWorker.html.

Alternatives

I think using web-sys is the safest approach but I could be missing something.

Additional context

N/A

@EstebanBorai EstebanBorai added the enhancement New feature or request label Oct 9, 2024
@Jinxit
Copy link
Owner

Jinxit commented Oct 9, 2024

hi there! i haven't had much time for this crate recently, and i don't personally have a need for shared workers. but as long as it follows the style of the current code i'd be happy to merge it if you'd like to build it yourself.

i suspect it could use the same WebWorker trait and maybe the same ChannelWorker implementation, but with a different mode of construction where it checks if it already exists or not, turning it from an scsc channel to an mpsc. the tricky part is how to handle responses, should they be copied to all tabs or just sent to one? maybe that should be configurable? not sure. EDIT: i looked at how SharedWorkers actually work in the browser, seems like they get this ports list of connection that it can use to send messages to one or all tabs, so it has to be a new kind of worker. the current workers are very request-response oriented, is that your usecase too or are you intending to have some sort of scheduled trigger in the worker? i feel like that's going to decide how the worker function should look.

if you're on leptos 0.6 you can start from the main branch, if you're on leptos 0.7 i'd start from the send-sync branch. let me know if you're starting from send-sync and i'll put some effort into merging that ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants