The functions that listen to events act as Observers. In an event-driven application, there is generally a main loop that listens for events, and then triggers a callback function when one of those events is detected.Īlthough events look quite similar to callbacks, the difference lies in the fact that callback functions are called when an asynchronous function returns its result, whereas event handling works on the observer pattern. As soon as Node starts its server, it simply initiates its variables, declares functions and then simply waits for the event to occur. Node.js uses events heavily and it is also one of the reasons why Node.js is pretty fast compared to other similar technologies. Node thread keeps an event loop and whenever a task gets completed, it fires the corresponding event which signals the event-listener function to execute. Every API of Node.js is asynchronous and being single-threaded, they use async function calls to maintain concurrency. Node.js is a single-threaded application, but it can support concurrency via the concept of event and callbacks.
0 Comments
Leave a Reply. |