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

109
Visualizações
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 à 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