function exit(code) {
  code = code || 0;
  // Safe exits process after all streams are drained.
  // file descriptor flag.
  var fds = 0;
  // exits process when stdout (1) and sdterr(2) are both drained.
  function tryToExit() {
    if (fds & 1 && fds & 2) {
      process.exit(code);
    }
  }

  [process.stdout, process.stderr].forEach(function (std) {
    var fd = std.fd;
    if (!std.bufferSize) {
      // bufferSize equals 0 means current stream is drained.
      fds = fds | fd;
    } else if (std.write) {
      // Appends nothing to the std queue, but will trigger `tryToExit` event on `drain`.
      std.write("", function () {
        fds = fds | fd;
        tryToExit();
      });
    }
    // Does not write anything more.
    delete std.write;
  });
  tryToExit();
}
/**
 * In order to prevent STDs from close before all data written
 * @param {number} code exit code
 */
In order to prevent STDs from close before all data written
@param {number} code exit code
In order to prevent STDs from close before all data written @param { number } code exit code
function exit(code) {
  code = code || 0;
  var fds = 0;
  function tryToExit() {
    if (fds & 1 && fds & 2) {
      process.exit(code);
    }
  }
  [process.stdout, process.stderr].forEach(function (std) {
    var fd = std.fd;
    if (!std.bufferSize) {
      fds = fds | fd;
    } else if (std.write) {
      std.write("", function () {
        fds = fds | fd;
        tryToExit();
      });
    }
    delete std.write;
  });
  tryToExit();
}
function exit ( code ) { code = code || 0 ; var fds = 0 ; function tryToExit ( ) { if ( fds & 1 && fds & 2 ) { process . exit ( code ) ; } } [ process . stdout , process . stderr ] . forEach ( function ( std ) { var fd = std . fd ; if ( ! std . bufferSize ) { fds = fds | fd ; } else if ( std . write ) { std . write ( "" , function ( ) { fds = fds | fd ; tryToExit ( ) ; } ) ; } delete std . write ; } ) ; tryToExit ( ) ; }
In order to prevent STDs from close before all data written
 @param {number} code exit code
In order to prevent STDs from close before all data written @param { number } code exit code
// Safe exits process after all streams are drained. // file descriptor flag. // exits process when stdout (1) and sdterr(2) are both drained. // bufferSize equals 0 means current stream is drained. // Appends nothing to the std queue, but will trigger `tryToExit` event on `drain`. // Does not write anything more.