Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
Do NodeJS setInterval()s queue up?

There's a classical problem with setInterval() in browsers - if some JS code or other browser process takes too long to complete, several callback invocations might get "backed up" and you suddenly end with your callback executed multiple times in quick succession.

Often this is not what is desired when setInterval() is used. It's a typical use case when you want AT LEAST some interval of time to pass between invocations. The workaround to this is to use setTimeout() instead and only schedule the next invocation when the previous is completed.

This works well but also is extra code and might be confusing for someone who does not understand the issue.

I know that NodeJS works differently than browsers, but I cannot find any information on this particular aspect. Does NodeJS also exhibit the same behavior, or does it guarantee a minimum time between invocations when using setInterval()?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Looks like it.

start = () => {
  console.log(Date.now(), 'interval started');
  setInterval(() => console.log(Date.now(), '-'), 1000);
}
busy = (n) => {
  console.log(Date.now(), 'busy started');
  for (let i = 1; i < n; i++) Math.sqrt(i, 7);
  console.log(Date.now(), 'busy done');
}

start();
busy(1e10); // this takes a while; nothing is printed, because this keeps the node.js thread busy

Output:

1642469880773 interval started
1642469880776 busy started
1642469888272 busy done
1642469888272 -
1642469889273 -
1642469890274 -

Note the long gap between busy start and done, and how no backlog of interval callbacks seem to follow.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!