Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda