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

224
Views
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 answers
Answer question

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 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!