M
M
Maxla932016-10-30 20:47:25
JavaScript
Maxla93, 2016-10-30 20:47:25

What is the correct way to get a response from the main process?

There is a master process that runs fork() (child processes).
They communicate by the method for the main:

example1.on('message', function(worker) {
// Сообщения которые приходят от дочернего
});

process.on('message', function(master) {
// Сообщения которые приходят от главного процесса - дочернему
});

The task is that the child sends data to the main.
process.send('send_itemsCounters');
The master catches this data (and sends its data to the child):
if(worker == 'send_itemsCounters'){
   example1.send({itemsCounters:itemsCounters,sss:1}); 
}

And the child has a certain function that should run only when the answer comes from the main one.
How to implement it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question