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

112
Vistas
Await not waiting for other awaits to finish in Async function

Learning JS a little bit and having a problem on a project that I have been working on. I have 2 forEach function that the second one relies on the first one for a variable. I want to await both of them so that the second one only runs once the first forEach has finished. I was hoping for some tips (I know that this can't be the most efficient way of doing this lol

// test data to show structure
const staff = [{
    steamid: 'STEAM_0:1:1111111',
    server: 'testing'}];

const setStaffInfo = async function () {
  try {
    await staff.forEach(async (item) => {
    // this getSteamID64 is a fetch to convert steamID to steamID64
    // this works fine
      const steamid64 = await util.getSteamID64(item.steamid);
      if (steamid64) item.steamid64 = steamid64;
    });
    
    // PROBLEM! I believe this is running before the steamid64 is set in the prior forEach function
    await staff.forEach((el) => {
      if (el.server === "testing" && el.steamid64) {
        el.sits = 5;
      }
    });

  } catch (err) {
    console.log(err);
  }
};

about 4 years ago · Juan Pablo Isaza
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