signalmanager
ES6 JS classes for socket client and server message passing
Installation
npm install signalmanager --save
Usage
Prevent closing until your code approves it
Add shutdown handlers for SIGINT and SIGTERM.
This is in case multiple "threads" or classes need to
do individual checks before closing. (Obviously no program can withstand SIGKILL though)
Add a request handler first. It will be responsible for passing into the
callback true or false for if it approves the shutdown.
If all processes approve, all shutdown handlers are run then exited.
If any function/class passes false for REJECTION, the shutdown is canceled;
and no shutdown handlers are run.
var SignalManager = require('signalmanager');
SignalManager.addShutdownApprovalHandler(() => {
if (somethingImportantHasNotFinishedYet) {
return false;
} else {
return true;
}
});
SignalManager.addShutdownHandler(() => {
if (isAnEmergencySomethingImportantIsStillRunning) {
return false;
} else {
someSocket.close();
someFile.close();
someEmail.send();
return true;
}
});
Credits
http://c-cfalcon.rhcloud.com