3 ms·
Can you clarify "main thread"? Do you have a code example? Asking as Node is single threaded. Thanks
by zebnyc 4y ago
Can you clarify "main thread"? Do you have a code example?
Asking as Node is single threaded.
Thanks
- numlock86 4y agoMost likely using the cluster module and your favorite IPC module. https://nodejs.org/api/cluster.html https://nodejs.org/api/cluster.html
- yrgulation 4y agoThat or https://nodejs.org/api/worker_threads.html#worker-threads https://nodejs.org/api/worker_threads.html#worker-threads
- ksbrooksjr 4y agoMy go-to method of inter-process communication in Node without using any third party modules is to just use process.send[1] to a send a message to the main thread, and then have it forward messages to the workers in the cluster, which you can listen for using the message event [2]. [1] https://nodejs.org/api/process.html#processsendmessage-sendhandle-options-callback https://nodejs.org/api/process.html#processsendmessage-sendh... [2] https://nodejs.org/api/process.html#event-message https://nodejs.org/api/process.html#event-message
- christophilus 4y agoUsing cluster and worker threads. The code is here, but completely undocumented, as I’ve been side tracked by a few other things[0]. I’m currently looking into porting that project to Bun, so it’s possibly dead in its current form. I was planning on turning that into a library, but Bun nerd sniped me. You need the “hey” tool to run the benchmarks[1] the way that I was running them. [0] https://github.com/chrisdavies/sql3 https://github.com/chrisdavies/sql3 [1] https://github.com/rakyll/hey https://github.com/rakyll/hey