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

240
Views
How to properly request a server on loop?

I have an array of cities. A pretty big array. For every city in the array I need to make 2 requests to my server - 1 request to get the current weather for the city, and another 1 to get today news. For each of those 2 requests there is a special API endpoint. How do I get all the neccessary information properly? I mean:

  1. don't make too many requests per second
  2. the final result should store information in the same order as the cities are stored in the array
  3. if some of the requests are failed, don't stop requesting for the other cities (not like in Promise.all)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use Promise.allSettled() and then use a timeout to wait for a certain period of time and redo the same. Make sure to use also a request timeout (so when a server is not responding for a long time, you may want to abort).

Here is an example:

const myFunc = async () => {
  await Promise.allSettled([ ... ]);
  setTimeout(myFunc, 1000);
};
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!