How do I create a non-blocking asynchronous function? Below is what I\'m trying to achieve but my program is still blocking...
var sys = require(\"sys\");
f
Try to answer this question based on the event loop model (the core of node.js).
setTimeout(doSomething,0). Yes, setTimeout will add a task into the task queue. And after 0 second, the time is up. Event loop checks the task queues and finds the task is done, and its callback function doSomething is ready to run.
The above process is async.
One thing needs to note here is: the callback function doSomething runs on the main thread(or the single thread) of node.js, and the event loop is also running on this thread. Without a doubt, the while(true) loop totally block the thread.