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

282
Visualizações
Resolve multiple network calls at once in react

I want to download time-series data from a rest service. Currently, I have the following implementation

async function getTimeSeriesQuery(i) {
  // Using this to show how gql is being used
  appollo.query(getChunkQueryOptions(i))
}

var promises = []

for(var i = 0; i < numberChunks; i++) {
  promises.push(getTimeSeriesQuery(i))
}
const data = Promise.all(promises)

image.pngImgae of chunked queries

I expected the promises to take the same amount of time as one promise but it seems to scale with the number of promises I have in the list of promises

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The exection time of each promise has nothing to do with number of promises on the list nor with the exection time of another promise.

Promise.all doesn't begin Promises execution, it just waits for them to finish. If all of the Promises already were resolved earlier (for example if all HTTP requests already have finished), then the Promise.all will resolve to a value almost immediately, because there is simply nothing to wait for anymore. Promise.all, gives in a list the results of each promise.

Example : We have a liste of 2 promises : - 1 takes 10s - 2 taked 1s Promise.all will take 10s.

about 4 years ago · Juan Pablo Isaza Relatório

0

As mentioned, the duration of each request cannot be determined beforehand.

If you want, though, to wait for all to complete, you need to add the promises in your array (which the snippet you posted does not). And if you want the data in a variable, you will need to either use the .then or await for the results.

So you need to return the actual promise from your getTimeSeriesQuery

async function getTimeSeriesQuery(i) {
  // Using this to show how gql is being used
  // was missing the return
  return appollo.query(getChunkQueryOptions(i))
}

var promises = []

for(var i = 0; i < numberChunks; i++) {
  promises.push(getTimeSeriesQuery(i))
}

const data = await Promise.all(promises)
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