Jer*_*Fox 14 javascript timer delay settimeout node.js
我正在寻找一种在N秒后在nodejs中运行一些代码的方法.
尝试了setTimeout(),但它似乎完全阻止它,直到时间结束但这不是我想要的,因为我的服务器仍在发送和接收事件.
有什么建议?
小智 18
实际上,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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6979 次 |
| 最近记录: |