Guest User

Untitled

a guest
Dec 11th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. let _isTerminating = false;
  2. let _isTerminatingForce = 5; // Initialize with the maximum number of SIGINTs to force terminate.
  3. process.on('SIGINT', () => {
  4. if (_isTerminating) {
  5. if (_isTerminatingForce > 1) {
  6. --_isTerminatingForce;
  7. process.stderr.write('\n\n\nGot SIGINT, hit it ' + _isTerminatingForce + ' more times to force terminate.\n\n\n');
  8. } else {
  9. process.stderr.write('\n\n\nGot SIGINT, force terminated.\n\n\n');
  10. process.exit(-1); // eslint-disable-line no-process-exit
  11. }
  12. } else {
  13. process.stderr.write('\n\n\nGot SIGINT, will terminate gracefully. Please wait.\n\n\n');
  14. _isTerminating = true;
  15. }
  16. });
  17. // Use `_isTerminating` in the points of async code where termination is not harmful.
Add Comment
Please, Sign In to add comment