I have a javascript that calls a function each 1 minute. That function sends a bot on the web looking for information to update on my database (quotes, to be exact).
So basically, sometime it’s pretty fast and other times the servers dont answer fast… Let’s say I have 100 seeks like this to make each 1 minute. They could take anywhere between 10 seconds to 1 minute+ to execute.
My question is : If the function is still fetching and/or waiting for data and I call it again (remember I call it each 1 minute), WILL IT CANCEL THE FIRST CALL to the function? If not, then will they simply stack and finish before starting the other one or will they run at the same time?
Thanks a bunch!
You may be interested in using Prototype’s Function.PeriodicalExecuter to help you manage functions that take a long time to complete.
If including all of Prototype seems like overkill and you want to implement the functionality by hand, you could either have a boolean-flag that you set when an instance of the function is running; or a counter that is incremented at the head of the function, and decremented before it returns, giving you the total number of instances of that function.
If you are interested in using Prototype, another function that may help you out is Ajax.PeriodicalUpdater.