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

190
Views
How to delay a async function in a loop?

The axios_simulation fucntion represents the api call. I want to loop 10 times and call the api in an interval of 1 second. But the api is called 10 times simultaneously after 1 second ([Done] exited with code=0 in 1.135 seconds) How to fix this problem?

function axios_simulation() {
  return new Promise(function(resolve, reject) {
    console.log("request the api");
    resolve('success');
  }
  );
}

function run_in_interval(interval) {
  for (var i = 0; i < 10; i++) {
    axios_simulation().then(function(result) {
      console.log(result);
    });
    sleep(interval);
  }
}

function sleep(milliseconds) {
  setTimeout(function() {
  }
  , milliseconds);
}

run_in_interval(1000);
about 4 years ago · Juan Pablo Isaza
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!