You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to establish communication between two Workers using MessageChannel in Bun, the messages are not being transmitted between the Workers, while the same code works correctly in Node.js.
Reproduction
import{Worker,isMainThread,parentPort,MessageChannel,threadId}from'worker_threads';import{fileURLToPath}from'url';if(isMainThread){constworker1=newWorker(fileURLToPath(import.meta.url));constworker2=newWorker(fileURLToPath(import.meta.url));const{ port1, port2 }=newMessageChannel();worker1.postMessage({port: port1,workerId: 1},[port1]);worker2.postMessage({port: port2,workerId: 2},[port2]);worker1.on('message',(msg)=>console.log('Main thread received from worker1:',msg));worker2.on('message',(msg)=>console.log('Main thread received from worker2:',msg));}else{letworkerPort;letmyWorkerId;parentPort.on('message',({ port, workerId })=>{workerPort=port;myWorkerId=workerId;workerPort.on('message',(msg)=>{console.log(`Worker ${myWorkerId} received:`,msg);workerPort.postMessage(`Reply from worker ${myWorkerId}`);});workerPort.postMessage(`Hello from worker ${myWorkerId}`);});parentPort.postMessage(`Worker ${threadId} started`);}
Expected Behavior
Workers should be able to communicate with each other through MessageChannel ports
Messages sent through MessageChannel ports should be received by the other Worker
Similar behavior to Node.js implementation
Actual Behavior
Messages are not being transmitted between Workers
No errors are thrown
Communication does not work as expected
Environment
Bun Version: 1.2.2
Operating System: macOS
Additional Context
The same code works correctly in Node.js
This affects the ability to implement direct Worker-to-Worker communication in Bun applications
The text was updated successfully, but these errors were encountered:
What version of Bun is running?
1.2.2
What steps can reproduce the bug?
When trying to establish communication between two Workers using MessageChannel in Bun, the messages are not being transmitted between the Workers, while the same code works correctly in Node.js.
Reproduction
Expected Behavior
Actual Behavior
Environment
Additional Context
The text was updated successfully, but these errors were encountered: