Node.js event loop understanding (with a diagram)

Viewed 1583

I've read this and this, watched this...

I've made a diagram of how I understand it:

enter image description here

  • Javascript callbacks (functions) can be present in the current queue, check queue, close callbacks queue, timers queue and I/O callbacks queue.
  • Js code gets executed only from the current queue one function (task/job) at a time.
  • Js code executed at the moment can add microtasks (jobs) to the current queue to be executed after itself and macrotasks (tasks) to the check queue. It can add tasks to other queues only inderectly by asking the API to do it.
  • Idle, prepare phase is used for some internal node js business (maybe like garbage collection).
  • Poll phase polls threads from the thread pool and fills the queues with appropriate callbacks.
  • Idle, prepare and poll phases don't have queues for js callbacks associated with them.
  • (four) Threads in the thread pool are all identical and have no specialization.
  • Event loop takes and executes tasks one by one from each queue until it's empty then moves on to the next queue.
  • Tasks in the queues don't have any jobs (microservices) associated with them. Jobs are created only during execution of a task or another job and are present only in the current task queue.

Is that understanding right or am I missing something?

MS Power Point .pptx file with the diagram can be found here.

1 Answers
Related