lib/Slave.js
/**
   * Gracefully shuts down the slave, after all remaning messages are received.
   * @param {Function=} done A callback for completion.
   * @return {Promise} A promise for completion.
   */
Gracefully shuts down the slave, after all remaning messages are received.
@param {Function=} done A callback for completion.
@return {Promise} A promise for completion.
Gracefully shuts down the slave after all remaning messages are received . @param { Function = } done A callback for completion . @return { Promise } A promise for completion .
shutdown(...args) {
    const done = args._.getCallback();
    this[settings].rejectingRequests = true;
    delete slaves[this.id];
    if (this.pendingRequests === 0) return this.close(done);
    this.emit('shutdown', this, ...args);
    return new Promise((resolve, reject) => {
      this.on('response', () => {
        if (this.pendingRequests === 0) {
          this.close()
            .then(status => {
              done.call(this, null, status);
              resolve(status);
            })
            .catch(e => {
              done.call(this, e, null);
              reject(e);
            });
        }
      });
    });
  }
shutdown ( ... args ) { const done = args . _ . getCallback ( ) ; this [ settings ] . rejectingRequests = true ; delete slaves [ this . id ] ; if ( this . pendingRequests === 0 ) return this . close ( done ) ; this . emit ( 'shutdown' , this , ... args ) ; return new Promise ( ( resolve , reject ) => { this . on ( 'response' , ( ) => { if ( this . pendingRequests === 0 ) { this . close ( ) . then ( status => { done . call ( this , null , status ) ; resolve ( status ) ; } ) . catch ( e => { done . call ( this , e , null ) ; reject ( e ) ; } ) ; } } ) ; } ) ; }
Gracefully shuts down the slave, after all remaning messages are received.
Gracefully shuts down the slave after all remaning messages are received .
/**
     * Emitted when the slave is scheduled for shutdown.
     * @event shutting-down
     * @argument {Slave} slave The slave.
     * @argument {...*} args The arguments passed to shutdown
     */