JavaScript is not multi-threaded. So if your task 1 a for loop that last 20 seconds, tasks 2-3-4 are not ran concurently.
So really what happens is that each function calls are queued one after another and the execution of the response of async functions are only added when the promise is completed or the callback is called.
Which allows the program to keep executing other functions while it “waits” for the async function.
And this is why I love NodeJs for a server. It is very easy to write async code in JavaScript.
38
u/NoStranger6 May 01 '20
Except that’s not necessarly true for javascript.
JavaScript is not multi-threaded. So if your task 1 a for loop that last 20 seconds, tasks 2-3-4 are not ran concurently.
So really what happens is that each function calls are queued one after another and the execution of the response of async functions are only added when the promise is completed or the callback is called.
Which allows the program to keep executing other functions while it “waits” for the async function.
And this is why I love NodeJs for a server. It is very easy to write async code in JavaScript.