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

147
Views
JavaScript ejecuta múltiples funciones asíncronas una por una

tengo funcion:

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

y

 function setLangToData(data) { lang = data }

y quiero ejecutar getLangFile("en_gb", "1.18") , y cuando obtenga los datos, ejecute getLangFile("de_de", "1.18") y luego someAnotherFunction()

Sé que la solución es algo con devolución de llamada o promesas, pero no lo entiendo y quiero aprenderlo más tarde. Tengo un proyecto simple para principiantes, pero no puede funcionar sin esto. Gracias por cualquier ayuda

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

Puedes intentar algo como esto,

 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!