I am using jQuery(Latest release) and have a function called “calculate()” which gets called every time a field is edited and the field exited(blur etc). (To allow “dynamic” calculation”)
The calculation takes under 4 seconds to complete, but if the user changes another element on the form before the calculation is complete, then they are queued and the function is called again after the current action is complete.
As I can’t stop the function from processing once it’s started, is it possible to delay the function by a couple of seconds and then each time a form element is interacted with, add to the timer.
I don’t think this is possible, but thoguht i’d give it a shot.
I know I could do:
setTimeout(function(){ ... }, 4000);
but I would need a way to add to this timer. (i.e. The timer has 1 second left, I click on a field and I want the timer to go back to 4 seconds)
What I would do is something like this:
This way you don’t run concurrent
calculate()functions. No need for endless timers, and if there are calculations “queued” then they will be calculated after the first calculate function stops… rather than waiting 4s each time. What happens when you change your calculate function and it takes longer?Hope this helps.