Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

async/await vs callback resolution order, given shared asynchronicity

If async/await & callbacks are both asynchronous, why are async/await resolved before callbacks?

For example (hypothetical, in practice its obviously not so cut-and-dry)

// classic callback
doSomething("./some-path", (err, data) => {...})

// This resolves with higher priority
await someAsyncFunction()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In short, callbacks go to the end of the line in the regular job queue. async/await goes through the message queue, which is akin to a "fast pass" lane at an amusement park.

This article has some great examples and does a pretty good job covering this exact topic.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading