I am learning through the architecture of Node.js. I have following questions.
The event loop is, first and foremost, a high-level concept that's a fundamental part of the JavaScript programming model. Practically, every V8 embedder needs to implement an event loop. V8 provides a default implementation, which embedders can replace or extend.
I don't understand the question. (I guess the answer is "yes", but what's the difference between "event loop" and "event queue"?)
None. (Except that Node.js uses both.)
Yes, the event loop is single-threaded.
Yes, browsers have an event loop too (see question 1).
This is actually not as simple as given in the post selected as the answer. I hope my remarks will be a bit more exact. Hopefully I understood Sam Roberts (IBM) correctly in his talk on the Node event loop.
To view the talk yourself you can go here: https://www.youtube.com/watch?v=P9csgxBgaZ8
This is an addon to the answer given by @jmrk
Libuv delegates tasks to the underlying operating system. The operating system then becomes responsible for sending a notification when an event occurs you are listening to. It does this for a lot of the operations you perform in Node. Like: sockets (net/dgram/http/tls/https/child_process pipes, stdin, out, err), timeouts and intervals.
However not everything can be delagated like this to the underlying OS. Sometimes it is required to create a thread (there are 4 treads by default but you can change this using UV_THREADPOOL_SIZE). Not pollable are file system operations, dns.lookup() and some crypto functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With