DEV Community

Discussion on: This is why your Node.js application is slow

Collapse
 
imichaelowolabi profile image
Michael Owolabi

Thank you @darkwiiplayer for your comment. Yes, I agree that there's a way to use async/await to ensure the other part of the program gets executed while the result of the async operation is being processed however, there's also a way as shown in the article where the event loop is blocked and no other part of the program will get executed until the result of the asynchronous operation becomes available as a result of using it wrongly.

Collapse
 
ats1999 profile image
Rahul kumar

no other part of the program will get executed until the result

This is not correct await will not block execution of the whole program. It'll pause the execution of the function.

Collapse
 
sannajammeh profile image
Sanna Jammeh

The event loop is NOT blocked by any async function unless you’re executing blocking code. Await is not blocking code.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Again, that's not what you show in the article. You're not blocking the event loop, you're just waiting for a timer twice in a row.

Thread Thread
 
dununubatman profile image
Joshua Dale

DarkWiiPlayer is correct. In your first example you changed the behavior so your promises are effectively running in parallel instead of running sequentially in your asynchronous example. The event loop isn’t being blocked, you just told it to wait for the first promise to complete before executing the second.

Thread Thread
 
imichaelowolabi profile image
Michael Owolabi • Edited

Thank you so much @darkwiiplayer for your follow up response and you @dununubatman for your further explanation. Yes, you're correct and I agree with you that I did not show that in the article and I am going to update that part in the article as pointed out.
I really appreciate 🙏🏻