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

138
Vistas
Async/await with multiple for loops

I am having a hard time wrapping my head around how aysnc/await works for my specific scenario. I have some for loops that I want to run parallel of each other but I also have other for loops that are dependent on the data create from one of the parallel for loops.

Loop 1 {
/* Delete some rows from a SQL Table */
}

Loop 2 {
/* Delete some rows from a SQL Table */
}

Loop 3 {
/* Add some rows to a SQL Table */
}

Loop 4 {
/* Update some rows from a SQL Table */
}

What I want to happen is Loop 1, Loop 2, and Loop 3 run in parallel instead of sequentially. I don't want Loop 4 to run until Loop 3 has finished. How could this be achieved with async/await. I am trying to improve runtime of this code but I need to use for loops to iterate through data in the database.

Alternatively, if there is a way to reduce the time complexity using a different method instead of for loops I am open to suggestions.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

await Promise.all(promiseLoop1, promiseLoop2, promiseLoop3);

await promiseLoop4;

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

Edit:

In addition, you can build the SQL command string using loops but only call SQL once.

You may also want to look into SQL Transactions:

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/transactions-transact-sql?view=sql-server-ver15

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