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

138
Visualizações
How can I retry these promise(s) when there is a network failure?

I have a create-react-app (CRA) using Node and React and Express.

When the user logs in, it will initiate React context like this:

initiateContext = async () => { 

    const promises_1 = [
        this.getBreakthrus(), //check done
        this.getBadges(), //check done
        this.getChapter(), //check done
    ]

    const promises_2 = [
        this.getContext(), //check done
        this.getTeam(), //check done
        this.getTeams(), //check done
        this.getTeamData(), //check done
        this.getFacilitators(), //check done
        this.getNextQuestion(), //check done
    ]

    await Promise.all(promises_1)
    await Promise.all(promises_2);
    this.setLobbyView("profile")
}

These functions load all the data for the application, and initiate the lobby view for the user.

The Problem: When the user is using a VPN connection, sometimes the context data doesn't load. However, the lobby view does load, so the user sees the lobby, but all the data is empty.

How can I make this function more flexible, to handle network failures / retries?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like your actual issue is a race condition. Your code should be:

initiateContext = async () => { 


    await Promise.all([
        this.getBreakthrus(), //check done
        this.getBadges(), //check done
        this.getChapter(), //check done
    ]);

    //this will now run AFTER the above
    await Promise.all([
        this.getContext(), //check done
        this.getTeam(), //check done
        this.getTeams(), //check done
        this.getTeamData(), //check done
        this.getFacilitators(), //check done
        this.getNextQuestion(), //check done
    ]);
    this.setLobbyView("profile");
};

Also, semi-colons matter

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