Skip to content

Instantly share code, notes, and snippets.

@jsmrcaga
Created February 16, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmrcaga/c84236eece0c27baffec28e79896d4a4 to your computer and use it in GitHub Desktop.
Save jsmrcaga/c84236eece0c27baffec28e79896d4a4 to your computer and use it in GitHub Desktop.
// INSTRUCTIONS
/*
* 1) Run node sigint.js and call ctrl-c, then wait 1 second (for process to exit)
* Expected output: SIGINT 1
*
* 2) Run npm start (see end of file for example, which runs node sigint.js) and call ctrl-c, then wait 1 second (for process to exit)
* Expected output SIGINT 1
* Unexpected output SIGINT 2
*/
let called = 0;
// do not auto kill
setTimeout(() => {}, 1000000);
process.on('SIGINT', () => {
console.log('SIGINT', ++called);
setTimeout(() => {
process.exit(0);
}, 1000);
});
// NPM package.json example
// here for accessibility purposes
// {
// "scripts": {
// "start": "node sigint.js"
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment