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

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

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