Open rchiodo opened 2 years ago
I believe there's a solution to this, use a BroadcastChannel instead. (supported by node and web browsers).
Essentially every worker uses the BroadcastChannel instead. When sending messages, a target could be set, something like so:
{
"dest": "main",
"src": "worker-<threadid>"
}
Main thread would listen on the same broadcast channel and handle messages with "dest" : "main"
.
Worker threads would listen on the same broadcast channel and handle messages with "dest": "worker-<threadid>"
where the thread id matches their own.
I believe that would let messages to go to and from an arbitrary worker to the main thread.
Suppose you have something like so:
Main Thread - Extension code Worker 1 - Extension sub piece, which starts Worker 2 Worker 2 - Needs to use the sync api
Worker 2 cannot communicate with the Main Thread because its MessageChannel is only with Worker 1.
For CPython I have this exact situation when trying to run the debugger:
Worker 2 and 3 cannot send messages to the Main Thread.