Sign in

Some people get confused about how much code an await statement actually covers. That is, how much code has to wait before the await statement resolves. The answer is pretty simple. Only the code that is after the await statement and part of the async function get’s blocked until the await statement resolves. Let’s see an example.

In the picture above we can see the first log executes, then because of the await statement the entire async function gets blocked from further execution before 1 second . But that doesn’t block the main thread. The interpreter jumps on to the second function and executes the log statement there. And after that, the promise in the first function resolves, the log statement gets printed, and the interpreter continues to log the very last statement of the first function.

KMA Badshah

Passionate web and mobile developer with over 2 years of experience in building anything from SPA's to OS agnostic mobile apps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store