如何判断setInterval是否是阻止应用退出的最后一件事
How to tell if a setInterval is the last thing that's stopping an app from exiting
是否有一种方法可以知道在进程自动退出之前节点必须完成多少任务,因为没有其他事情可做?我想使用setInterval
,但只有在应用程序繁忙的时候。我不想阻止进程自动触发退出事件:
// an app that does serveral things, then finishes
// this should only be active whilst the app is busy:
var interval = setInterval(function(){
// some stuff
// how to determine if the interval is the last thing to complete?
if(process.lastThingToDo == interval)
clearInterval(interval);
}, 2500);
如果您想使用一个定时器,它仍然会像普通定时器一样工作,但不会阻止进程退出,您可以在它上使用.unref()
。
// an app that does serveral things, then finishes
// this should only be active whilst the app is busy:
var interval = setInterval(function(){
// some stuff
// how to determine if the interval is the last thing to complete?
if(process.lastThingToDo == interval)
clearInterval(interval);
}, 2500);
// add this .unref() call to make it so the process will not wait for this timer
// before exiting, but the timer will otherwise work normally
interval.unref();
查看node.js文档中.unref()
的定时器
相关文章:
- 表追加而不附加最后一个元素
- 弹出窗口出现,然后退出
- Amd,希望确保某个东西总是最后执行
- 键入最后一位数字后自动提交
- 无法在Ionic select中预先选择最后一个选项
- 动态插入的表:JQuery未检测到最后一行
- 退出全屏不起作用
- 基于两个条件退出While循环
- 为什么画布形状只在3个画布中的最后一个画布上渲染
- 如何准确执行加载脚本&退出弹出窗口
- Jquery append oly获取循环Rails中的最后一个elemen
- 使用Booklet Jquery插件,我如何验证最后一页是否显示
- 如何创建更好的方式来维护基于我的代码访问的最后一个页面
- dataTables-如何自定义分页类型以显示最后一个页码后面的省略号,
- 多维关联数组的最后一个索引
- firefox插件:退出不工作的应用程序观察器
- 无法获取vis.js最后一个或第一个选定的网络节点
- 循环以检查数组中的最后一个图像
- 如何创建Google Analytics事件跟踪来记录访问者退出网站之前最后关注的表单字段
- 如何判断setInterval是否是阻止应用退出的最后一件事