我正在寻找一种在 N 秒后在 nodejs 中运行一些代码的方法。
试过 setTimeout() 但它似乎完全阻止它直到时间结束但这不是我想要的,因为我的服务器仍在发送和接收事件。
有什么建议吗?
最佳答案
其实setTimeout
是异步的,所以不会阻塞。
setTimeout(function(){
// this code will only run when time has ellapsed
}, n * 1000);
// this code will not block, and will only run at the time
关于javascript - 使用nodejs在一定时间后运行函数/代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24621457/