Sha256: 3e6fd8b32d04e28cba141f9d0954456eade678f20accd8dc44fb542baaf30962

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

/*
 * exit
 * https://github.com/cowboy/node-exit
 *
 * Copyright (c) 2013 "Cowboy" Ben Alman
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function exit(exitCode, streams) {
  if (!streams) { streams = [process.stdout, process.stderr]; }
  var drainCount = 0;
  // Actually exit if all streams are drained.
  function tryToExit() {
    if (drainCount === streams.length) {
      process.exit(exitCode);
    }
  }
  streams.forEach(function(stream) {
    // Count drained streams now, but monitor non-drained streams.
    if (stream.bufferSize === 0) {
      drainCount++;
    } else {
      stream.write('', 'utf-8', function() {
        drainCount++;
        tryToExit();
      });
    }
    // Prevent further writing.
    stream.write = function() {};
  });
  // If all streams were already drained, exit now.
  tryToExit();
  // In Windows, when run as a Node.js child process, a script utilizing
  // this library might just exit with a 0 exit code, regardless. This code,
  // despite the fact that it looks a bit crazy, appears to fix that.
  process.on('exit', function() {
    process.exit(exitCode);
  });
};

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/exit/lib/exit.js
locomotivecms-3.4.0 app/javascript/node_modules/exit/lib/exit.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/exit/lib/exit.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/exit/lib/exit.js
exercism-analysis-0.1.1 vendor/javascript/node_modules/jshint/node_modules/exit/lib/exit.js
entangled-0.0.16 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.15 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.14 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.13 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.12 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.11 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
entangled-0.0.10 spec/dummy/public/node_modules/grunt/node_modules/exit/lib/exit.js
trans-0.5.10 template/node_modules/grunt/node_modules/exit/lib/exit.js
trans-0.5.9 template/node_modules/grunt/node_modules/exit/lib/exit.js
cssesc-source-0.1.0 vendor/node_modules/grunt/node_modules/exit/lib/exit.js