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

108
Views
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
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!