Skip to content

Instantly share code, notes, and snippets.

@jhsea3do
Created March 6, 2019 07:21
Show Gist options
  • Save jhsea3do/e7f8dbe4cda50cd47daffb3103580ced to your computer and use it in GitHub Desktop.
Save jhsea3do/e7f8dbe4cda50cd47daffb3103580ced to your computer and use it in GitHub Desktop.
process test
let threads = new Set;
let x = 0;
let d = console.log
let s = ()=>{
for(let t of threads) {
clearTimeout(t);
}
}
let c = (...args)=>{
console.log('quit', ...args);
if(args && args[0] == 'SIGINT' && args[1] == 2) {
d('! unsupport ctrl+c, please try again');
x++;
if(x < 2) {
throw 'custom error'
}
d('! ok pass')
}
s();
};
process.on('exit', ()=>{ d('>', 'shutdown'); });
process.on('SIGHUP', (...args)=>{ c(...args); });
process.on('SIGINT', (...args)=>{ c(...args); });
process.on('SIGTERM', (...args)=>{ c(...args); });
process.on('uncaughtException', (e) => {
process.stdout.write(`! some error: ${e}\n`);
});
let t = setTimeout(()=>(1), 10000)
threads.add(t);
process.nextTick(() => {
d('>', 'wait...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment