catdad / grandma

👵 fully programmable stress testing framework
20 stars 4 forks source link

grandma can only run for 24 days #157

Open catdad opened 7 years ago

catdad commented 7 years ago

setTimeout has a thing... any larger value overflows and results in a negative, which causes setTimeout to complete immediately.

Thanks Greg.


Some libs, in order of how well they are actually implemented:

link notes
tellnes/long-timeout no arguments, but I rarely use those anyway
mikermcneil/set-dateout Mike likes reading StackOverflow... anyway, no way to cancel these, but never the less, a cool idea
trs/set-long-timeout Node 6+, so can't use for grandma, but a good model
gabru-md commented 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

catdad commented 6 years ago

Blocked by #129.