Behind the scenes in a node, how createServer http module createServer (and its callback) interact with the event loop? Is it possible to build functionality similar to createServer alone in the user area, or will it require a change in the node system code?
That is, my general understanding of the node event loop is
- Event loop
- Node is looking for any callbacks to run
- Node performs these callbacks
- Event loops repeat again, process repeats ad-infinitum
What I'm still a little fuzzy is how createServer fits into the event loop. If I do something like this
var http = require('http'); // create an http server and handle with a simple hello world message var server = http.createServer(function (request, response) { //... });
I suggest node execute my callback whenever an HTTP request arrives. This is not like the event loop model that I understand. It seems that there are several non-userland and non-event loops that listen for HTTP requests and then trigger my callback if you enter.
Put another way - if Iβm thinking about implementing my version of the createServer version, I canβt figure out how to do this, since any callback I plan will run once. Does createServer only setTimeout or setInterval to constantly recheck an incoming HTTP request? Or is there something lower, more efficient. I understand that I do not need to fully understand this in order to write efficient node code, but I am curious how the underlying system was implemented.
(I tried following in Node source , but this is slow, since I am not familiar with the node modular system or the deprecated w / r / t assumptions for encoding templates deep in the system code)
source share