Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda