Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
96c5967a35 | |||
c21c10d7f2 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartexit",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartexit",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"private": false,
|
||||
"description": "do things before one exists a process",
|
||||
"main": "dist/index.js",
|
||||
|
11
ts/index.ts
11
ts/index.ts
@ -43,20 +43,25 @@ export class SmartExit {
|
||||
|
||||
constructor() {
|
||||
// do app specific cleaning before exiting
|
||||
process.on('exit', async () => {
|
||||
process.on('exit', async (code) => {
|
||||
if (code === 0) {
|
||||
console.log('SMARTEXIT: Process wants to exit');
|
||||
await this.killAll();
|
||||
}
|
||||
});
|
||||
|
||||
// catch ctrl+c event and exit normally
|
||||
process.on('SIGINT', async () => {
|
||||
console.log('Ctrl-C...');
|
||||
console.log('SMARTEXIT: Ctrl-C... or SIGINT signal received!');
|
||||
await this.killAll();
|
||||
});
|
||||
|
||||
//catch uncaught exceptions, trace, then exit normally
|
||||
process.on('uncaughtException', async err => {
|
||||
console.log('Ctrl-C...');
|
||||
console.log('SMARTEXIT: uncaught exception...');
|
||||
console.log(err);
|
||||
await this.killAll();
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user