node.js: while loop callback not working as expected
Knowing that while Node.js is working asynchronously, writing something like this: function sleep() { var stop = new Date().getTime(); while(new Date().getTime < stop + 15000) { ; } } sleep(); console.log("done"); ...would call the sleep(), block the server for the duration of the while loop (15secs) and just THEN print "done" to the console. As far as I understand, this is because Node.js is giving JavaScript only access to the main thread, and therefore this kidn of thing would halt further execution. So I understand the solution to this is to use callbacks: function sleep(callback) { var