Hello!

So, I think I made a design mistake.

I have a child process worker, that receives some data and sends back the 
results to dynamically attached listener.

Simplified code:



    //app.js
    var worker = childProcess.fork('./app_modules/workers/worker1.js');
    worker.setMaxListeners(0);
    require('./app_modules/sockets-user/foobar.js')(io, worker);


    //foobar.js
    io.sockets.on('connection', function (socket) {
      socket.on('trigger', function (data) {
        worker.send(data);
        worker.once('message', function(responseData) {
        
          //here I get a response from worker
          socket.emit('response', responseData);
        
        });
      });
    });



It was working great until I discovered that If socket.on('trigger' is 
triggered at the very exact moment by different users every listener would 
receive the same message.

I could change worker.once to worker.on and filter incoming messages but 
its not really a fix. I would have to destroy every listener after it was 
used to prevent them from adding up and I don't know if it is even possible.


I did pass the worker object like that, because I thought I could pass it 
anywhere it was needed, now I feel like I was wrong. How should I approach 
this problem?










-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/2d1c01d3-e663-48b8-bbb3-46e99c74f213%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to