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

221
Views
How to pause a setInterval, wait for the execution of another function and resume the setInterval

I'm trying to loop a function with a setInterval and then, when a condition is hitted:

  1. Pause the setInterval loop
  2. Call and execute an async function
  3. Resume the setInterval loop

What's the best way to do it in Javascript? I have something like this:

var refreshId = setInterval(Myfunction, 5);

function  Myfunction(){
---do something---

if (conditionIsHitted){
externalFunction();}
}
 ---resume the setInterval loop again
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you cant "pause" a setinterval. nor a setTimeout. but you can stop it and start it again later. like start with a 10 sec timeout. stop it 2 seconds later. and restart it later with a 8 sec timeout.

// run something after 10 sec - will never actually be runned, because stopped later
let timeout = setTimeout(function() {
    console.log('10 sec elapsed');
}, 10000);

// stop after 2 seconds and relaunch the work to be done
setTimeout(function() {
    clearTimeout(timeout);

    setTimeout(function() {
        console.log('10 sec elapsed');
    }, 8000);
}, 2000);

about 4 years ago · Juan Pablo Isaza 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!