The event loop is a core programming concept that coordinates task execution with asynchronous event handling. Widely found in: JavaScript, Node.js, Browser runtimes, Flutter, java, Game engines and some high-performance services such as Redis and Nginx
The advantages of a normal synchronous design are linearity and simplicity, but the disadvantage is that the entire program execution can easily get stuck on some time-consuming operations.
console . log ( 1 );
readSomeFiles (); // time-consuming operations
console . log ( 2 );
Enter fullscreen mode
Exit fullscreen mode
the CPU spends most of its time waiting for I/O
threads are blocked
concurrency is poor
So, in order to better utilize the CPU and more rationally allocate timer tasks and simple ordinary tasks, the concept of the event loop was born.
Systems that use event loops typically operate like this (Think about how you usually write JavaScript code):
console . log ( 1 );
setTimeout (() => console . log ( 2 ));
Promise . resolve ().…