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

135
Visualizações
how do I use async await in a regular for loop

I have a function that accepts a game found from a mongodb database via mongoose and the number of bots to add to the game object. the problem is after running the function only one bot object is being saved to the document even thought numOfBots is 3

async function addBot(game, numOfBots){

  for(index = 0; index < numOfBots; index++){
    let bot = {nickName: "Bot"}
    game.players.push(bot)
    game = await game.save()
  }
  return game
}

// elsewhere in another async function 
await addBot(game,3)

How can I use async await correctly in a regular for loop?

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