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
I need to add a way to send messages from workers to main thread:
The only possibility I see right now with Piscina, is to send a messagePort when running a task and use it to communicate (Or use a broadcastChannel but only for node 17+).
In my case, I want to use a single messagePort per worker, set at startup of the worker and use it when initializing inside the worker and before running tasks... But there is no currently easy way to add a messagePort per worker at startup built in Piscina...
I wonder if it would be possible to use the already existing built in messages ports of Piscina to add this feature ?
Something like this:
Adding a new kind of message that the worker can send:
exportinterfaceGenericMessage{
data: any;}
Use it to send messages from worker at any stage:
let message : GenericMessage;parentPort.postMessage(message);
And handle such messages at pool level to expose it:
Certainly a possibility. It can get a bit tricky because of timing. The messages you are sending are not guaranteed to arrive and be processed (because the worker could be torn down first) and it's likely not a good idea for those messages to be related to any tasks (or to have individual tasks depend on them) or else you can run into nasty race conditions and inconsistencies.
I need to add a way to send messages from workers to main thread:
The only possibility I see right now with Piscina, is to send a messagePort when running a task and use it to communicate (Or use a broadcastChannel but only for node 17+).
In my case, I want to use a single messagePort per worker, set at startup of the worker and use it when initializing inside the worker and before running tasks... But there is no currently easy way to add a messagePort per worker at startup built in Piscina...
I wonder if it would be possible to use the already existing built in messages ports of Piscina to add this feature ?
Something like this:
Adding a new kind of message that the worker can send:
Use it to send messages from worker at any stage:
And handle such messages at pool level to expose it:
Do this make sense ?
The text was updated successfully, but these errors were encountered: