www.webdeveloper.com
Results 1 to 3 of 3

Thread: Question about setInterval calling a function faster than the function can execute

  1. #1
    Join Date
    Sep 2006
    Posts
    93

    Question about setInterval calling a function faster than the function can execute

    I have a pretty simple question.

    Can setInterval run it's assigned function again before it's previous function call has finished?

    Code:
    setInterval(foo, 100);
    
    function foo() {
    // lots of heavy code that sometimes takes more than 100 miliseconds
    }
    I know it's very easy to prevent this by having a true/false variable to tell if the function is currently running or not, but, I'm wondering if browsers already prevent this problem (and the, in what way?) or if it just let's it run the function over and over?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    If the function makes changes to the rendered page, the next call may not reflect the changes. Also, the time interval will not be accurate- but setInterval cannot call the next iteration until the previous one has returned.

  3. #3
    Join Date
    Sep 2006
    Posts
    93
    Thanks, that was exactly what I was wondering.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles