Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda