Comparing version 1.0.0 to 1.1.0
29
index.js
'use strict'; | ||
module.exports = function (cb) { | ||
var exit = function (sig) { | ||
cb(); | ||
if (sig) { | ||
process.exit(128); | ||
} | ||
}; | ||
var cbs = []; | ||
process.once('exit', exit); | ||
process.once('SIGINT', exit.bind(null, true)); | ||
process.once('SIGTERM', exit.bind(null, true)); | ||
function exit(sig) { | ||
cbs.forEach(function (el) { | ||
el(); | ||
}); | ||
if (sig) { | ||
process.exit(128); | ||
} | ||
}; | ||
module.exports = function (cb) { | ||
cbs.push(cb); | ||
if (cbs.length === 1) { | ||
process.once('exit', exit); | ||
process.once('SIGINT', exit.bind(null, true)); | ||
process.once('SIGTERM', exit.bind(null, true)); | ||
} | ||
}; |
{ | ||
"name": "exit-hook", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Run some code when the process exits", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,5 +26,11 @@ # exit-hook [![Build Status](https://travis-ci.org/sindresorhus/exit-hook.svg?branch=master)](https://travis-ci.org/sindresorhus/exit-hook) | ||
// you can add multiple hooks, even across files | ||
exitHook(function () { | ||
console.log('exiting 2'); | ||
}); | ||
throw new Error('unicorns'); | ||
//=> exiting | ||
//=> exiting 2 | ||
``` | ||
@@ -31,0 +37,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1681
18
41