Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let _isTerminating = false;
- let _isTerminatingForce = 5; // Initialize with the maximum number of SIGINTs to force terminate.
- process.on('SIGINT', () => {
- if (_isTerminating) {
- if (_isTerminatingForce > 1) {
- --_isTerminatingForce;
- process.stderr.write('\n\n\nGot SIGINT, hit it ' + _isTerminatingForce + ' more times to force terminate.\n\n\n');
- } else {
- process.stderr.write('\n\n\nGot SIGINT, force terminated.\n\n\n');
- process.exit(-1); // eslint-disable-line no-process-exit
- }
- } else {
- process.stderr.write('\n\n\nGot SIGINT, will terminate gracefully. Please wait.\n\n\n');
- _isTerminating = true;
- }
- });
- // Use `_isTerminating` in the points of async code where termination is not harmful.
Add Comment
Please, Sign In to add comment