threads.js icon indicating copy to clipboard operation
threads.js copied to clipboard

Support for worker-to-worker communication

Open andywer opened this issue 5 years ago • 4 comments

Allow exposing a worker's functionality to other workers using MessageChannel.

Workers must handle a new meta message transferring a pair of message ports and listen on it / send to it, too, not just the main thread.

To Do

  • Allow communication using arbitrary MessagePort instances
  • Allow passing a MessagePort to spawn() (maybe rather create a new function)
  • Add Thread.isTerminatable()
  • Export MessageChannel & MessagePort

andywer avatar Oct 05 '19 22:10 andywer

any update on this? would love to leverage MessageChannel for worker to worker support, bypassing the main thread

hyusetiawan avatar Apr 18 '20 10:04 hyusetiawan

Haven't found time to work on that yet, but it's good to know that there is interest in that 👍

andywer avatar Apr 18 '20 19:04 andywer

Seems currently we can manually pass in MessageChannel as options, to setup communication between two workers?

linonetwo avatar Oct 23 '22 14:10 linonetwo

@linonetwo Do you have a code snippet demonstrating communication between two workers?

trasherdk avatar Nov 20 '22 00:11 trasherdk