Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda