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

131
Visualizações
Why is the async function execution executed synchronously

enter image description here enter image description here

const c = async() => console.log("2")
const a = async() => {
  console.log("1")
  await c()
  console.log("4")
}
const b = () => console.log("3");
console.log("start")
a();
b();

I would expect the sequence here to be 3 1 4 2, but apparently it is not. Async function seem to execute synchronously and be added to the callstack UNTIL they return, and that is when the rest is added to the event queue. Why is that and why is it not instantly added to the event queue?

Link to ECMA spec & other reads also greatly appreciated

This seem to explain why 1 is printed first, but not why the 2 is printed second, since by that answer it should return a promise on the FIRST await, but it actually executes b synchronously: When does async function actually return a pending promise?

about 4 years ago · Juan Pablo Isaza
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