It works this way:
The drim function registers an anonymous callback (function(err,data)) to be executed later (presumably when it is complete). It also schedules its own asynchronous operation (tell the interpreter that it needs to drim something).
You run the while loop
The interpreter is waiting for the end of script to see if has anything else to do (drim something and when that is done at a much later time run the scheduled callback).
... there is no number 4 because the while loop never completes therefore the end of script is never reached therefore the interpreter doesn't get the chance to run anything on its own.
In most other languages like C or Python the asynchronous library requires you to execute your own function to run the eventloop. Something like this:
async_function(callback);
eventloop.run(); // this allows the async function to work
In those languages it's obvious why inserting a while loop before running the eventloop means the eventloop never runs:
async_function(callback);
while (1) { /* do nothing */ }
eventloop.run(); // never gets run
In javascript, the eventloop is not a library, it's built-in. Therefore the eventloop.run is executed silently at the end of the script:
async_function(callback);
// eventloop runs here
Additional Answer
To get the semantics of your while loop (waiting for a flag to be set) working asynchronously you can always replace it with a setInterval or setTimeout loop:
setInterval(function(){
if (flag == false) {
console.log('Hey');
}
},10); // check 100 times per second
To stop the setInterval just call clearInterval:
var loop = setInterval(function(){
if (flag == false) {
console.log('Hey');
}
else {
clearInterval(loop); // stop the loop
}
},10);