Revised Question
I would like to know how the event loop of nodejs (whatever underlying implementation it is, may it be v8, libuv, libev) loops without exhausting the CPU. As the code example below shows, a sleep call is inserted in order to "free" the CPU and prevent the while loop using up the CPU. Since someone has already pointed out that it is not the case, then I would like to know what mechanism is employed in nodejs (or its underlying libraries) for such purpose?
Linking to relative sections of the source code is welcome. Thanks.
Original Question
I am asking about the nodejs internals: I would like to know if there is any sleep time between the ticks in nodejs' event loop.
In other words, I assume nodejs internals look like the code below, I would like to know what is the value of sometime
, if any.
while(true) {
for(event in queue) handleEvent(event);
sleep(sometime);
}
I made such assumption because I believe there must exist some kind of sleeping such that the while loop will not exhaust the CPU.