breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.01k stars 78 forks source link

[discussion] Send message to child process #154

Closed ChristianFranke closed 2 years ago

ChristianFranke commented 2 years ago

What would you like to discuss?

How do I send messages to the children from my parent process? Conversely, I do it with postMessage, but from parent to child I have not read anything.

Otherwise, I will try https://nodejs.org/api/worker_threads.html#worker_threads_class_messagechannel once, but I think there may also be a Bree solution if one direction already works (Stop signals work from Parent -> Child too).

Checklist

shadowgate15 commented 2 years ago

You can use the following: https://nodejs.org/api/worker_threads.html#workerpostmessagevalue-transferlist.

All the workers are stored in an object keyed by name under bree.workers. Therefore all you have to do is call bree.workers[jobName].postMessage('my message'); in order to communicate from the parent to the worker.