Tag: 析构函数

NodeJS析构函数

代码: function terminator(sig) { if (typeof sig === "string") { console.log('Received %s – terminating Node server …', sig); process.exit(1); }; console.log('Node server stopped.'); }; process.on('exit', function() { terminator(); }); function terminatorSetup(element, index, array) { process.on(element, function() { terminator(element); }); }; ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGPIPE', 'SIGTERM'].forEach(terminatorSetup); 不知何故,这不适用于Windows,退出与Ctrl + […]