lib/Slave.js
/**
 * Sets up various event handlers for a newly created slave process.
 * @param {Slave} slave The Slave object to setup the event handler for.
 * @param {ChildProcess} child The actual child process associated with this slave.
 * @param {Object} options Options to initialize the slave with.
 * @return {undefined}
 */
Sets up various event handlers for a newly created slave process.
@param {Slave} slave The Slave object to setup the event handler for.
@param {ChildProcess} child The actual child process associated with this slave.
@param {Object} options Options to initialize the slave with.
@return {undefined}
Sets up various event handlers for a newly created slave process . @param { Slave } slave The Slave object to setup the event handler for . @param { ChildProcess } child The actual child process associated with this slave . @param { Object } options Options to initialize the slave with . @return { undefined }
function initializeSlaveEventsWithSlaveAndChildProcess(slave, child, options) {
  const setSlaveExitedToTrue = () => {
    slave.emit('slave child process exited');
    cleanupSlaveReferences(slave);
  };
  child.on('message', slaveMessageListener);
  child.on('error', function onSpawnError(e) { 
    slave[settings].spawnError = e;
    cleanupSlaveReferences(slave);
    if (slave.listenerCount('spawn error') === 0) {
      throw e;
    } else {
      slave.emit('spawn error', e);
    }
  });
  child.on('close', () => {
    setSlaveExitedToTrue();
    slave.emit('closed');
  });
  child.on('exit', () => {
    setSlaveExitedToTrue();
    slave.emit('exited');
  });
  if (typeof options.forkOptions === 'object' && options.forkOptions.silent === true) {
    child.stdout.on('data', d => slave.emit('stdout', d));
    child.stderr.on('data', d => slave.emit('stderr', d));
  }
}
function initializeSlaveEventsWithSlaveAndChildProcess ( slave , child , options ) { const setSlaveExitedToTrue = ( ) => { slave . emit ( 'slave child process exited' ) ; cleanupSlaveReferences ( slave ) ; } ; child . on ( 'message' , slaveMessageListener ) ; child . on ( 'error' , function onSpawnError ( e ) { slave [ settings ] . spawnError = e ; cleanupSlaveReferences ( slave ) ; if ( slave . listenerCount ( 'spawn error' ) === 0 ) { throw e ; } else { slave . emit ( 'spawn error' , e ) ; } } ) ; child . on ( 'close' , ( ) => { setSlaveExitedToTrue ( ) ; slave . emit ( 'closed' ) ; } ) ; child . on ( 'exit' , ( ) => { setSlaveExitedToTrue ( ) ; slave . emit ( 'exited' ) ; } ) ; if ( typeof options . forkOptions === 'object' && options . forkOptions . silent === true ) { child . stdout . on ( 'data' , d => slave . emit ( 'stdout' , d ) ) ; child . stderr . on ( 'data' , d => slave . emit ( 'stderr' , d ) ) ; } }
Sets up various event handlers for a newly created slave process.
Sets up various event handlers for a newly created slave process .
/**
     * Emitted when the actual slave ChildProcess exits.
     * @event slave child process exited
     */ // If the child fails to spawn... // eslint-disable-line prefer-arrow-callback /**
       * Emited when the slave process fails to properly spawn.
       * @argument {Error} e The error tht occured during spawn.
       * @event spawn error
       */ // Set connected to false when the child closes, exits, or is disconnected. /**
     * Emited when the slave process closes.
     * @event closed
     */ /**
     * Emited when the slave process exits (is either killed or closed).
     * @event exited
     */ /**
     * Emited when the slave process writes to the stdout. This event is only triggered
     * if forkOptions.slient: true was passed to the slave initialization options.
     * @event stdout
     * @argument {Buffer} data The data from the slave's stdout
     */ /**
     * Emited when the slave process writes to the stderr. This event is only triggered
     * if forkOptions.slient: true was passed to the slave initialization options.
     * @event stderr
     * @argument {Buffer} data The data from the slave's stdout
     */