[英]Node.js setTimeout with callbacks
I'm running a node.js app and have a process that runs every 500ms. 我正在运行一个node.js应用,并且有一个每500毫秒运行一次的进程。 There's a lot of logic that's being done and at times, we found it could run over 500ms - this caused problems when using a setInterval.
有很多逻辑要做,有时我们发现它可以运行500毫秒以上-这在使用setInterval时引起问题。
We redesigned this to use setTimeout with a callback such as this: 我们将其重新设计为将setTimeout与这样的回调一起使用:
var start = function() {
self.performProcesses(function() {
setTimeout(function() {
start();
}, 500);
});
}
start();
The problem is sometimes this stops, meaning somewhere along the road a callback from performProcesses
is not being hit. 问题是有时这会停止,这意味着在路上的某个地方没有遇到来自
performProcesses
的回调。 There are thousands of lines of code that reach multiple objects and files. 成千上万的代码行可以到达多个对象和文件。
Would anyone recommend a good way to try to debug this and isolate where the break may be? 有人会推荐一种好的方法来尝试调试此问题并隔离中断的位置吗?
Thanks! 谢谢!
When I program in JavaScript I use Aptana . 当我用JavaScript编程时,我使用Aptana 。 It is part of a collection called Appcelerator, which is pretty much Eclipse.
它是名为Appcelerator的集合的一部分,该集合几乎是Eclipse。 Aptana let's you develop and debug in JavaScript, so you can StepInto, StepOver, and whatever..
Aptana让您使用JavaScript开发和调试,因此您可以使用StepInto,StepOver等。
Have you tried web-inspector ? 您是否尝试过网络检查器 ?
You can also try Paul Irish anim shim at loop controlling. 您也可以在循环控制中尝试Paul Irish动画补片 。 If you call
requestAnimFrame
after self.performProcess
, it will be called at interval of 500ms. 如果在
self.performProcess
之后调用requestAnimFrame
,它将以500ms的间隔被调用。
var requestAnimFrame = function (callback) { setTimeout(callback, 500); };
(function animloop () {
self.performProcesses();
requestAnimFrame(animloop);
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.