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

80
Visualizações
javascript async await for function before continuing

I have a helper function that calls other functions. I want the called functions to finish before continuing on in the helper function.

currently they are both changing things at the same time.

helperDikjstras = async() => {
  //do stuff
  await this.colorVisited(visitedNodes); // I want this function to finish before continuing
  await this.colorPath(path);

  //EDIT: I've also tried:
  this.colorVisited(visitedNodes).then(() => this.colorPath(path));
    return;
  }

  colorVisited = async (visitedNodes) => {
    //do stuff
    return;
  }

  colorPath = async (path) => {
    //do stuff
    return;
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Of course they do, that's the way it works. There is no "interupt" or pause capability in JavaScript. To achieve your goal, call your follow-on functions in the subsequent .then() of the first await.

Like so:

helperDikjstras = async() => {/*...*/}
colorVisited = async(visitedNodes, _callback) => {/*...*/}
colorPath = async(path) => {/*...*/}


helperDikjstras()
  .then(() => colorVisited(blah, halb))
  .then(() => colorPath(somePath));

If you needed to have other functions run after colorPath() you can simply add more...

helperDikjstras()
  .then(() => colorVisited(blah, halb))
  .then(() => colorPath(somePath))
  .then(() => doSomethingElse())
  .then(() => andAnother())
  .then(() => etc());
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