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

184
Vistas
Execute a function for x time

I'm looking for execute a function on nodejs with express for an exact time, and if the time have pass but the function don't end, the function stop.

I tried with setTimeOut. But it just works for execute a function after "x" time. I just need to execute the function for "x" time.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could set a Boolean variable and change its value after "x" of time, while checking the same variable in your function.


var Continue = true; // Our Boolean variable.
var x = 5000; // Execute the code for amount of milliseconds.

function canContinue(){
    return Continue;
}

var ourInterval = setInterval( function () {
    if(canContinue())
        console.log("Continue the code for one more second.")  
    else
        clearInterval( ourInterval )
}, 1000 );

setTimeout( function () {
    Continue = false;
}, x);

Hope that helps.

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