worker: populate BroadcastChannel MessageEvent source - #64334
worker: populate BroadcastChannel MessageEvent source#64334SudhansuBandha wants to merge 2 commits into
Conversation
8a9de03 to
98aaa6a
Compare
|
In the MDN documentation, https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/source
The threadId might be sufficient to work with the new API you folks were working on but I'm wondering if there's a technical limitation that makes diverging from the web api an absolute necessity? Ideally this would be the Worker Object, since one could immediately invoke |
jasnell
left a comment
There was a problem hiding this comment.
This is a breaking change making this a semver-major. It will need doc updates as well. I think we should instead try to find a way of doing this so that it's not a breaking change
|
Thanks for the review, @jasnell. I agree that changing |
|
@jasnell Source currently resolves to null. Why would this a breaking change when there is nobody in the forest to hear the tree fall? |
Populate the MessageEvent source property with the sender's worker thread ID for BroadcastChannel messages originating from worker threads. Fixes: nodejs#59053 Signed-off-by: Sudhansu Bandha <bandhasudhansu@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64334 +/- ##
========================================
Coverage 90.23% 90.23%
========================================
Files 741 741
Lines 241194 241355 +161
Branches 45432 45467 +35
========================================
+ Hits 217640 217798 +158
+ Misses 15129 15128 -1
- Partials 8425 8429 +4
🚀 New features to boost your workflow:
|
c3d7dcd to
e7d2e56
Compare
|
I have created an extension of the Undici based |
e7d2e56 to
e392e56
Compare
|
I'm not sure this is needed. The sender can always attach their own id if needed |
|
The API to send messages to a threadId is labeled experimental. The request was for the worker object to be set to source, so that messages could be sent directly, the same way web workers can. |
|
This PR does not fix #59053 It does something else that does not achieve feature parity with the HTML5 spec and is functionally unfit for purpose. |
|
I have updated the description of the ticket. After a long architecture conversation with another maintainer on the prometheus project, I've finally been able to articulate the problem here. Which is that there is currently no mechanism for composing Workers. If you create some workers for one task, you can manage them as interchangeable. If they need to ask any questions, they have to ask you. That's fine. But not fine when your organization has a second set of Workers with a different task. Now they have to talk to each other across Conway's Law boundaries and we have that law because not following it always ends in shouting and either tears or bloodshed. So, if I want to move caching to workers, and telemetry or image processing to other workers, and if they ever need to talk to each other, they need an opt-in mechanism to arrange their own communication channel between them, rather than calling a common parent and having them make the introduction. There isn't even a way in NodeJS to enumerate all of the currently running workers, so I can't write a module that goes looking around for your workers. Those two pieces of code have to be directly coupled. And they might already be 2 layers of separated in the system architecture when we figure it out. Which is a long way to say, "not composable". As near as I can tell, that's the whole reason BroadcastChannel exists. You just need two subsystems to know of a topic |
Populate the MessageEvent source property with the sender's worker thread ID for BroadcastChannel messages originating from worker threads.
Fixes: #59053