Open catdad opened 7 years ago
This is due to setTimeout
using a 32 bit int to store the delay so the max value allowed would be
2147483647
There is another way that i may propose: It is a very simple way/idea that may help you!
Let us consider that I want to run the code as mentioned below:
var myVar;
function myFunction(){
myVar = setTimeout(alertFunc,3000);
}
function alertFunc(){
alert("Just a try!");
}
// invoking myFunction()
myFunction()
The above code will simply generate an alert
box after 3000 milliseconds.
Now let us suppose the case is that I want that the alert
box must be created after ,lets say, some time which is an integral multiple of 3000.
One way would be rendering the above function:
function myFunction(){
myVar = setTimeout(alertFunc,3000*k);
}
where k
is the constant term/ integer.
But another possible way would be:
var myVar;
function myFunction(){
myVar = setTimeout(alertFunc,3000);
}
function alertFunc(){
alert("Just a try!");
}
var temp;
function repeat_myFunction(){
t = setTimeout(myFunction,k*1000)
}
// invoking new function
repeat_myFunction()
Now you will notice that your initial function
myFunction()
will now be invoked after k*initial
time.
For example put k*1000 = 2000
if you want the
myFunction()
to be repeated after TWICE the Initial time.
I hope this helps ! :D
Blocked by #129.
setTimeout
has a thing... any larger value overflows and results in a negative, which causessetTimeout
to complete immediately.Thanks Greg.
Some libs, in order of how well they are actually implemented: