Last active
February 6, 2024 05:21
-
-
Save ededejr/78963eb0e8a1410ab507fb1de5d13108 to your computer and use it in GitHub Desktop.
a utility function for executing callbacks on process exit in nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onProcessExit(callback: () => void): void { | |
[ | |
"SIGINT", | |
"SIGTERM", | |
"SIGHUP", | |
"SIGBREAK", | |
"unhandledRejection", | |
"uncaughtException", | |
].forEach((signal: string) => { | |
process.on(signal, () => { | |
callback(); | |
process.exit(0); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment