robtweed / ewd-qoper8

Node.js Message Queue and Multi-Process Manager
24 stars 5 forks source link

customQueue inside startWorker #3

Closed killmenot closed 7 years ago

killmenot commented 7 years ago

Hi @robtweed

Have a question regarding the following snippet of the code: https://github.com/robtweed/ewd-qoper8/blob/master/lib/master/proto/startWorker.js#L84-L95

if (!customQueue && finished) {
  //if (q.log) console.log('Master process has finished processing response from worker process ' + this.pid + ' which is back in available pool');
  // this check for worker is needed as custom onResponse may have stopped it
  if (worker) {
    worker.isAvailable = true;
    worker.time = new Date().getTime();
  }
  // now that this worker is available, process the queue again
  if (customQueue || q.queue.length > 0) {
    q.processQueue(customQueue);
  }     
}

I think once we enter in the condition !customQueue && finished that means that customQueue is false.

This means that if (customQueue || q.queue.length > 0) { can be simplified to if ( q.queue.length > 0) {

WDYT about this snippet?

robtweed commented 7 years ago

Interesting find. Actually I've kind of abandoned the customQueue mechanism anyway. But yes, you're right - that logic could be reduced to what you're suggesting :-)

killmenot commented 7 years ago

@robtweed can I remove customQueue from the module?

robtweed commented 7 years ago

Unfortunately not - it's been a possible option in the code and some people might be using it. Best to leave alone, but if any code optimisation is possible, then OK