Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

69
Visualizações
Multiple same Async Await function only Triggered the Last One

const fun = (x) => {
  console.log(`Meth... ${x}`);
  setTimeout(() => {
    onReceive(`Fun Received: ${x}`);
  }, 100);
  return x;
}

const publish = () => {
  return new Promise(resolve => {
    window.onReceive = (token) => {
      resolve(token);
    }
  });
}

const Inst = () => {
  const getAs = async(x) => {
    console.log(`Getting As ----- ${x}`);

    const res = await publish(fun(x));

    console.log(`Res is '${res}' ---- ${x}`);
  }

  return {
    getAs,
  }
}

const inst = Object.freeze(Inst());

const a = async() => {
  await inst.getAs(1);
  await inst.getAs(2);
  await inst.getAs(3);
  await inst.getAs(4);
  await inst.getAs(5);
};
a();

const b = async() => {
  await inst.getAs(4);
  await inst.getAs(5);
  await inst.getAs(6);
  await inst.getAs(7);
};
b();
// Comment or remove `b()` to see the different result in Console


I got confused why the function only called the last async await (b() from the example). Why inside of a() seems like didn't get called at all??

If I comment / remove b(), all inside of a() will get call.

Need helps / explanation to resolve such issue 🙏.

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda