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

411
Vistas
does microtask queue instructions have higher priority than root-level instructions?

const anotherAsync = async () => {
  console.log('Another async called');
  for (let i=0; i<=100000; i++) {

  }
  console.log('Another async finished');
};

const func = async () => {
  console.log('async func called');
  anotherAsync();
  console.log('async func finished');
};

const run = async () => {
  console.log('calling async func');
  await func();
  console.log('done');
};

run();

The result:

calling async func
async func called
Another async called
Another async finished
async func finished
done

Here, as you can see I am awaiting only on func function. anotherAsync is not awaited. So, logically I would assume async func finished and done to be printed before Another async called as anotherAsync() should be in microtask queue untill the callstack is not yet empty. But here it does not seem to be the case.
Will appreciate if someone can help me understand why Another async function is printed before async func finished

My assumption is that, anotherFunc is part of func which is why await on func does trigger an implicit await on anotherFunc or prioritizes the execution of those instructions for that function

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