Socket
Socket
Sign inDemoInstall

cleankill

Package Overview
Dependencies
0
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

.npmignore

75

index.js

@@ -11,42 +11,55 @@ /**

'use strict';
var interruptHandlers = [];
// Register a handler to occur on SIGINT. All handlers are passed a callback,
// and the process will be terminated once all handlers complete.
/**
* Register a handler to occur on SIGINT. All handlers are passed a callback,
* and the process will be terminated once all handlers complete.
*/
function onInterrupt(handler) {
interruptHandlers.push(handler);
interruptHandlers.push(handler);
}
// Call all interrupt handlers, and call the callback when they all complete.
exports.onInterrupt = onInterrupt;
/**
* Call all interrupt handlers, and call the callback when they all complete.
*
* Removes the list of interrupt handlers.
*/
function close(done) {
var numComplete = 0;
// You could cheat by calling callbacks multiple times, but that's your bug!
var total = interruptHandlers.length;
interruptHandlers.forEach(function(handler) {
handler(function() {
numComplete = numComplete + 1;
if (numComplete === total) done();
var numComplete = 0;
// You could cheat by calling callbacks multiple times, but that's your bug!
var total = interruptHandlers.length;
interruptHandlers.forEach(function (handler) {
handler(function () {
numComplete = numComplete + 1;
if (numComplete === total) {
done();
}
});
});
});
interruptHandlers = [];
interruptHandlers = [];
}
exports.close = close;
var interrupted = false;
// Behaves as if you sent a SIGINT to the process.
/**
* Calls all interrupt handlers, then exits with exit code 0.
*
* If called more than once it skips waiting for the interrupt handlers to
* finish and exits with exit code 1.
*
* This function is called when a SIGINT is received.
*/
function interrupt() {
if (interruptHandlers.length === 0) return process.exit();
if (interrupted) {
console.log('\nKilling process with extreme prejudice');
return process.exit(1);
} else {
interrupted = true;
}
close(process.exit.bind(process));
console.log('\nShutting down. Press ctrl-c again to kill immediately.');
if (interruptHandlers.length === 0) {
return process.exit(0);
}
if (interrupted) {
console.log('\nKilling process with extreme prejudice');
return process.exit(1);
}
else {
interrupted = true;
}
close(function () { return process.exit(0); });
console.log('\nShutting down. Press ctrl-c again to kill immediately.');
}
exports.interrupt = interrupt;
process.on('SIGINT', interrupt);
module.exports.close = close;
module.exports.interrupt = interrupt;
module.exports.onInterrupt = onInterrupt;
{
"name": "cleankill",
"version": "1.0.2",
"version": "1.0.3",
"description": "Hook SIGINT and cleanly shut down your async code",
"homepage": "https://github.com/PolymerLabs/cleankill",
"bugs": "https://github.com/PolymerLabs/cleankill/issues",
"license": {
"type": "BSD-3-Clause",
"url": "http://polymer.github.io/LICENSE.txt"
},
"license": "BSD-3-Clause",
"repository": {

@@ -15,3 +12,10 @@ "type": "git",

},
"main": "index.js"
"scripts": {
"prepublish": "tsc"
},
"main": "index.js",
"devDependencies": {
"typescript": "^1.8.10"
},
"typings": "./index.d.ts"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc