Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!