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

145
Views
JavaScript run multiple async functions one by one

I have function:

function getLangFile(name, version) {
  var lang;
  lang = "nothing";
  let url = "./" + version + "/" + name + ".json";
  fetch(url)
    .then((response) => response.text())
    .then((data) => {
      setLangToData(data);
    });
}

and

function setLangToData(data) {
   lang = data
}

and i want to run getLangFile("en_gb", "1.18"), and when it get the data, run getLangFile("de_de", "1.18") and then someAnotherFunction()

I know solution is something with callback or promises, but i don't understand it and i wanna learn it later. I have simple beginner project, but it can't work without this. Thanks for any help

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

async function test(){
  const res1 = await getLangFile("en_gb", "1.18");
  const res2 = await getLangFile("de_de", "1.18");
  const res3 = await someAnotherFunction();
}

doc:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

about 4 years ago · Juan Pablo Isaza Report

0

You can try something like this,

const makeHttp = function (url) {
  return new Promise(function (resolve, reject) {
    fetch(url).then((response) => {
      resolve(response.text());
    });
  });
};

(async function () {
  // 1st call
  await makeHttp("./version1/name.json");

  // 2nd call
  await makeHttp("./version2/name.json");
})();
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!