I use the below code to write code to query a web method in a specified interval.
now in the this.Poll function I have to do
this.tmo = setTimeo
You can use this handy little wrapper to execute a function periodically at given interval (1 sec by default):
function tick(func, interval) {
return (function() {
if(func())
setTimeout(arguments.callee, interval || 1000);
})();
}
The function is repeated until it returns false:
tick(function() {
if(should stop) return false;
do stuff
return true;
});
If the function is a method, make a closure as shown
// inside your object
var me = this;
tick(function() {
return me.doStuff();
});