cleankill
Advanced tools
Comparing version 1.0.2 to 1.0.3
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" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
10237
10
255
0
1
2