Skip to content

Conversation

@celluj34
Copy link

Hello! I will be up front, for 95% of this change, I used AI to do the work. I do not fully understand why workers are receiving messages intended for other workers, but I have verified in my codebase that this fix does work.

I have a main thread object, ServiceA, that creates a worker from another class, MainWorker. This worker creates three of its own workers, WorkerA, WorkerB, and WorkerC. Each of these expose an instance of their respective types: Comlink.expose(new <worker class>()) in their own file. The problem I encounter is, method calls to WorkerA also get sent to WorkerB and WorkerC, which throw errors in Comlink.expose due to rawValue.apply calling apply on undefined, because it can't find methodA on the other two workers.

I've added a console.warn, and I can see that those warnings are written when multiple workers are registered. This leads me to think that expose is still attempting to register incorrectly(?), but the fix does prevent those method calls on the incorrect worker. I would love to get this problem resolved in the main library, currently I'm using my own fork.

Thank you for your time! Please let me know if you have any comments, questions, etc.

Fixes #294, #450, #470, #568

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide Example of worker A calling Worker B via MessagePort/Comlink

1 participant