Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  81] [ 3]  / answers: 1 / hits: 10868  / 10 Years ago, tue, september 9, 2014, 12:00:00

Philip Roberts does a brilliant job explaining the browser event loop here providing a clear explanation between the call stack, event loop, task queue, and then outside threads like webapis. My question is do these parallel the equivalent components in the Node event loop and are they called basically the same thing. That is, when I make a call using Node's file and web i/o libraries, these are things that happen outside the stack whose callbacks are queued in a task queue?


More From » node.js

 Answers
6

...when I make a call using Node's file and web i/o libraries, these are things that happen outside the stack whose callbacks are queued in a task queue?




Yes, absolutely; they're asynchronous just like Ajax and setTimeout are asynchronous. They perform some operation outside of the call stack, and when they've finished that operation, they add an event to the queue to be processed by the event loop.



Node's API provides a kind of asynchronous no-op, setImmediate. For that function, the some operation I've mention above is do nothing, after which an item is immediately added to the end of the event queue.



There is a more powerful process.nextTick which adds an event to the front of the event queue, effectively cutting in line and making all other queued events wait. If called recursively, this can cause prolonged delay for other events (until reaching maxTickDepth).


[#42608] Monday, September 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulisa

Total Points: 436
Total Questions: 102
Total Answers: 123

Location: Palau
Member since Tue, May 30, 2023
1 Year ago
;