cuvidk cuvidk - 8 months ago 69
Node.js Question

Can a function / callback execution be interrupted by an external call?

I'm inside a callback function that does some very important operations, and it's very important for that callback to end before any other call can be raised from outside, so without interruptions. The question is: am I guaranteed that my callback function will execute to it's end without any interruptions, or due to the asynchronous nature of node the callback can be interrupted, so that an external call can be resolved, and after that resumed?


The ECMAScript runtime is a single-threaded execution environment. While operations can be taking place in other threads of the runtime host, the currently running call stack must terminate before other operations can be started on it. Callbacks are placed into an event queue (that is managed by the host) where they wait for the call stack to be idle. When that happens, the next callback in the queue is executed.