Javascript “为什么我的功能”;SIGINT";工作两次?
为什么我的函数“SIGINT”工作两次?我想在一段时间后关闭应用程序,我使用带递归的函数,但我在控制台“接收到SIGINT信号”中看到两个结果。如果我不使用递归,我只有一个结果Javascript “为什么我的功能”;SIGINT";工作两次?,javascript,node.js,Javascript,Node.js,为什么我的函数“SIGINT”工作两次?我想在一段时间后关闭应用程序,我使用带递归的函数,但我在控制台“接收到SIGINT信号”中看到两个结果。如果我不使用递归,我只有一个结果 async function checkActiveProcess(start_time){ active_set.status = 'stop' let now_data = new Date().getTime(); if (now_data - start_time > 5000){
async function checkActiveProcess(start_time){
active_set.status = 'stop'
let now_data = new Date().getTime();
if (now_data - start_time > 5000){
if (active_set.counter > 0){
active_set.counter -= 1
console.info(active_set.counter)
setTimeout(checkActiveProcess, 5000, start_time)
} else {
console.log('All ok')
process.exit(0);
}
} else {
console.log(`Sorry, not enough time`)
process.exit(0)
}
}
process.on('SIGINT', () => {
const start_time = new Date().getTime();
console.info('SIGINT signal received.');
setTimeout(checkActiveProcess, process.env.TIME/5, start_time)
});
我正在centos中运行应用程序,当我执行ctrl+C时,在控制台中我将看到下一个:
SIGINT signal received.
SIGINT signal received.
4
3
2
1
0
据我所知,函数工作两次,如何修复它?这是否回答了您的问题?不,我使用“node index.js”我不使用“npm start”