Created
March 6, 2019 07:21
-
-
Save jhsea3do/e7f8dbe4cda50cd47daffb3103580ced to your computer and use it in GitHub Desktop.
process test
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
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