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

410
Views
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
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!