Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4111786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:06:40+00:00 2026-05-20T22:06:40+00:00

A couple years ago I was warned against using setInterval for long periods of

  • 0

A couple years ago I was warned against using setInterval for long periods of time as it supposedly would cause the browser to hang if the called function ran longer than the designated interval, and would then not be able to catch up:

setInterval( function(){
  foo = 'bar_' + i++;
}, 1 );

Now, I’m aware that adding lots of code in a loop could cause the browser to hang anyway, and that blocking code like alert, prompt, and confirm will stop the code in it’s tracks, but is there any good reason to avoid setInterval?

Note: I am aware of how to do recursive setTimeout calls (as that’s what I’ve been using), this question is my trying to figure out if it’s still worth using them, or whether setInterval can be used safely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:06:40+00:00Added an answer on May 20, 2026 at 10:06 pm

    The reason setInterval is bad is because it will try to execute the code every X MS regardless of what’s going on in the thread. So if you have:

    setInterval( complexFunction, 1 ); // complexFunction takes >1 MS to complete
    

    …you may end up with setInterval trying to re-execute several times before even its own code is complete! However, you can use setTimeout similarly and avoid this problem:

    setTimeout( complexFunction, 1 );
    
    function complexFunction() {
      // complex code
      setTimeout( complexFunction, 1 );
    }
    

    …now complexFunction will only call itself again once its own code is complete, so if its own code takes longer than 1 MS to complete you won’t have any backlog to deal with like you would with setInterval

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A couple of years ago I was taught, that in real-time applications such as
A couple of years ago the media was rife with all sorts of articles
A couple of years ago, we had a graphic designer revamp our website. His
I wrote a C# application for a client a couple of years ago, but
Couple of years ago i used some tool to monitor what event messages were
A couple of years ago, before I knew about Stack Overflow, I was working
This question was asked a couple years ago and the answers give out-dated recommendations,
I have a to rewrite code written couple of years ago to work with
I have some code, which was written couple of years ago and works only
I have been using SourceMonitor on my project for a couple of years to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.