What's the Event Loop?
What's the Event Loop?
The Event Loop is a fundamental concept in Node.js that enables non-blocking I/O operations, allowing Node.js to perform asynchronous tasks such as reading from the filesystem, making network requests, and more. Despite JavaScript being single-threaded, the Event Loop facilitates concurrent operations by offloading operations to the system kernel whenever possible.
Phases of the Event Loop:
setTimeout()
and setInterval()
.setImmediate()
.setImmediate()
callbacks are invoked here.socket.on('close', ...)
.Each phase has a FIFO queue of callbacks to execute. The Event Loop enters a given phase, performs any operations specific to that phase, then executes callbacks in that phase's queue until the queue is exhausted or the maximum number of callbacks has executed[1][2][3][4][5][6].
Execution Order:
Role of process.nextTick()
and Microtasks:
process.nextTick()
all...middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào