lib/Pool.js
function Pool(script, options) {
  if (typeof script === 'string') {
    this.script = script || null;
  }
  else {
    this.script = null;
    options = script;
  }

  this.workers = [];  // queue with all workers
  this.tasks = [];    // queue with tasks awaiting execution

  options = options || {};

  this.forkArgs = options.forkArgs || [];
  this.forkOpts = options.forkOpts || {};
  this.debugPortStart = (options.debugPortStart || 43210);
  this.nodeWorker = options.nodeWorker;

  // configuration
  if (options && 'maxWorkers' in options) {
    validateMaxWorkers(options.maxWorkers);
    this.maxWorkers = options.maxWorkers;
  }
  else {
    this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);
  }

  if (options && 'minWorkers' in options) {
    if(options.minWorkers === 'max') {
      this.minWorkers = Math.max((environment.cpus || 4) - 1, 1);
    } else {
      validateMinWorkers(options.minWorkers);
      this.minWorkers = options.minWorkers;
      this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers);     // in case minWorkers is higher than maxWorkers
    }
    this._ensureMinWorkers();
  }

  this._boundNext = this._next.bind(this);


  if (this.nodeWorker === 'thread') {
    WorkerHandler.ensureWorkerThreads();
  }
}
function Pool(script, options) {
  if (typeof script === 'string') {
    this.script = script || null;
  }
  else {
    this.script = null;
    options = script;
  }

  this.workers = [];  // queue with all workers
  this.tasks = [];    // queue with tasks awaiting execution

  options = options || {};

  this.forkArgs = options.forkArgs || [];
  this.forkOpts = options.forkOpts || {};
  this.debugPortStart = (options.debugPortStart || 43210);
  this.nodeWorker = options.nodeWorker;

  // configuration
  if (options && 'maxWorkers' in options) {
    validateMaxWorkers(options.maxWorkers);
    this.maxWorkers = options.maxWorkers;
  }
  else {
    this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);
  }

  if (options && 'minWorkers' in options) {
    if(options.minWorkers === 'max') {
      this.minWorkers = Math.max((environment.cpus || 4) - 1, 1);
    } else {
      validateMinWorkers(options.minWorkers);
      this.minWorkers = options.minWorkers;
      this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers);     // in case minWorkers is higher than maxWorkers
    }
    this._ensureMinWorkers();
  }

  this._boundNext = this._next.bind(this);


  if (this.nodeWorker === 'thread') {
    WorkerHandler.ensureWorkerThreads();
  }
}
function Pool ( script , options ) { if ( typeof script === 'string' ) { this . script = script || null ; } else { this . script = null ; options = script ; } this . workers = [ ] ; // queue with all workers this . tasks = [ ] ; // queue with tasks awaiting execution options = options || { } ; this . forkArgs = options . forkArgs || [ ] ; this . forkOpts = options . forkOpts || { } ; this . debugPortStart = ( options . debugPortStart || 43210 ) ; this . nodeWorker = options . nodeWorker ; // configuration if ( options && 'maxWorkers' in options ) { validateMaxWorkers ( options . maxWorkers ) ; this . maxWorkers = options . maxWorkers ; } else { this . maxWorkers = Math . max ( ( environment . cpus || 4 ) - 1 , 1 ) ; } if ( options && 'minWorkers' in options ) { if ( options . minWorkers === 'max' ) { this . minWorkers = Math . max ( ( environment . cpus || 4 ) - 1 , 1 ) ; } else { validateMinWorkers ( options . minWorkers ) ; this . minWorkers = options . minWorkers ; this . maxWorkers = Math . max ( this . minWorkers , this . maxWorkers ) ; // in case minWorkers is higher than maxWorkers } this . _ensureMinWorkers ( ) ; } this . _boundNext = this . _next . bind ( this ) ; if ( this . nodeWorker === 'thread' ) { WorkerHandler . ensureWorkerThreads ( ) ; } }
A pool to manage workers
@param {String} [script]   Optional worker script
@param {Object} [options]  Available options: maxWorkers: Number
@constructor
A pool to manage workers