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

225
Vistas
Perform function if event is not called within time period

I have a data fetching program in nodejs, and I want it to perform a function if an event has not happened within a certain amount of time.

console.log("Fetching data.....");

// "verify" event called when data has been successfully found
fetcher.on("verify", function() {
    console.log("Data found!");
    process.exit(1);
});

So what I want to do is if the verify event is not called within 10 seconds, do console.log("Fetching the data is taking longer than expected");

How can I go about doing this?

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

0

Just set a timeout, and clear it when verify is called (or don't, since you are exiting the process anyways):

console.log("Fetching data.....");

const timeout = setTimeout(() => {
    console.log("Fetching the data is taking longer than expected");
}, 10000);

// "verify" event called when data has been successfully found
fetcher.on("verify", function() {
    clearTimeout(timeout);
    console.log("Data found!");
    process.exit(1);
});
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