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

105
Visualizações
JavaScript calling async function at the same time with different parameters

I have an async function “getResults” that performs fetch await, waits for result, then does something with the result.

If I call that async function “getResults” with 2 different parameters at the same time, wanting to fetch 2 different things, it will go ahead and perform only one of them (I guess the one that came in first)

async function getResults(id, source, destination) {
  let result1 = await fetch.listen({
    listen: id
  }, apiHost("api.gps.com", "someparam", source)) /* this would be fetch result with parameters from getLosAngelesRoute function */

  let result2 = /* here I would like to fetch with parameters from getWashingtonRoute function */
  if (result1 !== result2) {
      // do something
    }
  else {
    // do nothing
  }
}

function getLosAngelesRoute() {
  getResults("id1", "newYork", "losAngeles")
}

function getWashingtonRoute() {
  getResults("id2", "detroit", "washington")
}

The workaround fix is to have 2 different functions “getResultsA” and “getResultsB” and call them separately...

But is it possible to call function “getResults” with different parameters from functions getLosAngelesRoute and getWashingtonRoute at the same time, have it fetch await BOTH and then do something with both results all within one function?

Hope this makes sense.

Thank you for your valuable thoughts.

about 4 years ago · Santiago Gelvez
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