After reading a lot about NodeJS Event loop, I still have one doubt.
In our code, if NodeJS runtime finds any async call, it pushes it to task/message queue which runs on a background thread and V8 keeps executing our further code on main thread. Once that async task has been finished, node checks the call stack for empty. If call stack is empty, then only node brings that callback on main thread for processing. Otherwise it has to wait till call stack is empty.
Up to this point I assume, I am correct.
Doubt: If async task finishes and call stack is not empty, then callback will need to wait for the call stack to become empty. Now suppose, if there are so many calls in my call stack which may take lot of times (less than async task to finish) and async task has been finished earlier, then unnecessary it has to wait for the call stack to become empty.
Has Node been designed in this way only that callback needs to wait for the call stack to become empty ?