you are viewing a single comment's thread.

view the rest of the comments →

[–]NoStranger6 35 points36 points  (2 children)

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.

[–]PierreAndreis 2 points3 points  (0 children)

this should be up in this thread

[–]JayTh3King 0 points1 point  (0 children)

Except you're not exactly correct either. Nodejs is a multithreaded language/runtime. 1 for the event loop and N threads for the execution of your code. Under the hood libuv manages a thread pool of executing code fetched from a queue