Javascript setInterval - rate or delay? -


Whether the Javascript set interval method waits the specified interval (at least) between two hangs of a specific code, or is it Does the wait interrupt the execution of the last execution and the beginning of the next execution?

(Or, when compared to Java's scheduled Exporters service - this is set is similar to schedule ScheduleFixedRate () or Scheduling fixes () ?)

If you call, 1000 takes 100 milliseconds to run the code> set interval with milliseconds interval and callback code, the next callback after 900 milliseconds will be performed.

If the callback takes 1050 milliseconds, then the next one will set fire immediately after the end ( 50 millisecond delay ). This delay will be deposited.

So it's similar in the Java world. If you need behavior, then you should use the setTimeout () and callback must be restarted every time it is finished:

  function callback ( ) {// long-running code set timeout (callback, 1000); } SetTimeout (callback, 1000);   

will wait exactly 1000 milliseconds for the code given above callback () again, no matter how long it is to run .

Comments