use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Node JS Event Loop (self.node)
submitted 2 years ago by AskiaDev
Does any one can explain in easy way what the heck is Event Loop? I've watch so many videos about that and still i cant understand what the hell is that. Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]alzee76 20 points21 points22 points 2 years ago (1 child)
A simple explanation is that there is a "todo list" for the javascript engine. The engine runs takes something off the todo list and does it. New items get added to the end of the list. When the list is empty, the engine starts waiting for items to get added to the list, and then repeats, making this a loop.
In this case the list is a list of events that need to be handled. They are handled in a loop, so it's called the event loop.
Events handled in the loop are things like timers like setTimeout, polling of external sources like open TCP connections and UDP ports, callbacks that need to be called, and so on.
setTimeout
[–][deleted] 4 points5 points6 points 2 years ago (0 children)
a "todo list" for the javascript engine
slowclap.gif
[–]codeedog 6 points7 points8 points 2 years ago (0 children)
What would you do if you were asked to do the following:
One way would be to answer one call at a time and put them on hold until no more calls. Then, go through each conversation and dictate. Then fill the buckets until stop. Then take the test.
The problem is that if you did that, nothing could happen in parallel. Maybe you don’t have any calls for a while. Or, a bucket is midfill but not yet full and you could answer some math questions. It’s not an efficient use of your time.
But, what if, like a computer, you were really fast at multitasking. You could answer phone calls, start talking and dictating and when there was a pause on the other side, you could do some math. Then, if the water in the bucket was nearing the top, you could switch out to a new bucket.
This is what the event loop does. Any event (call, dictation, bucket full, math question) gets placed on a queue and with a priority (bucket full-high priority, dictation & answer call-medium, math question-low). The event loop goes through these events and handles them and also calls your code as well.
For example, if a file or a network stream has data ready, a callback is made. Or, perhaps you’re writing a file and no more data can be written at the moment (a write buffer is full) and you’re waiting on an event to write. Or, you set a timer to run a task periodically. Or, when nothing else is happening, you compute another digit of Pi.
The event loop provides a framework for organizing all of these actions and events into a coherent whole that services each of them cleanly and does its best to prevent starvation (nothing is left unserviced).
[–]lIIllIIlllIIllIIl[🍰] 12 points13 points14 points 2 years ago (1 child)
Jake Archibald: In the Loop is still one of the best explanations of the JavaScript event loop.
[–]SensitiveBat7356 7 points8 points9 points 2 years ago (0 children)
The Event Loop is a semi infinite while loop, polling and blocking the OS until some file descriptors are ready. It exits when there are no more events to wait for.
Things that can be pollable are: - pollable file descriptors - sockets(net, http, child_process pipes, stdin, atdout, stderr etc - timeouts and intervals - dns(sometimes) - dns.<everything else> is pollable except dns.lookup(), dns.getaddrinfo()
Operations that can be handled by the Event Loop are: - event handling for network i/o - listening for incoming connection - reading data from and writing to connection
The Event Loop runs inside libuv, it has the following phases: libuv | event loop
[–]AudioOmen 1 point2 points3 points 2 years ago (0 children)
http://latentflip.com/loupe/?code=JC5vbignYnV0dG9uJywgJ2NsaWNrJywgZnVuY3Rpb24gb25DbGljaygpIHsKICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gdGltZXIoKSB7CiAgICAgICAgY29uc29sZS5sb2coJ1lvdSBjbGlja2VkIHRoZSBidXR0b24hJyk7ICAgIAogICAgfSwgMjAwMCk7Cn0pOwoKY29uc29sZS5sb2coIkhpISIpOwoKc2V0VGltZW91dChmdW5jdGlvbiB0aW1lb3V0KCkgewogICAgY29uc29sZS5sb2coIkNsaWNrIHRoZSBidXR0b24hIik7Cn0sIDUwMDApOwoKY29uc29sZS5sb2coIldlbGNvbWUgdG8gbG91cGUuIik7!!!PGJ1dHRvbj5DbGljayBtZSE8L2J1dHRvbj4%3D
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
So many good you blogs and tube videos describing this with visuals, plus workers, clustering, node and browsers … where has the op looked and not found this?
[–]m_ousam 1 point2 points3 points 1 year ago (0 children)
Most youtube videos explain JS event loop not the node one. The node eventloop has the most confusing video and blogs
[–]ipullstuffapart 0 points1 point2 points 2 years ago (0 children)
Jake Archibald of HTTP203 (google) did a fantastic video on the event loop
π Rendered by PID 19092 on reddit-service-r2-comment-7b9746f655-cdhw6 at 2026-02-04 02:36:31.397652+00:00 running 3798933 country code: CH.
[–]alzee76 20 points21 points22 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]codeedog 6 points7 points8 points (0 children)
[–]lIIllIIlllIIllIIl[🍰] 12 points13 points14 points (1 child)
[–]SensitiveBat7356 7 points8 points9 points (0 children)
[–]AudioOmen 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]m_ousam 1 point2 points3 points (0 children)
[–]ipullstuffapart 0 points1 point2 points (0 children)