Event  Loop  ( Event loop or event polling )

Event Loop It's a program structure , For waiting and sending messages and events .

In short , Is to set two threads in the program : One is responsible for running the program itself , be called " The main thread "; The other is responsible for the main thread and other processes ( Mainly all kinds of I/O operation ) Communication for , go by the name of "Event Loop Threads "( It can be translated into " Message thread ").

The green part of the main thread above , Or running time , And the orange part means free time . Whenever I meet I/O When , The main thread lets Event Loop Thread to notify the corresponding I/O Program , And then it goes back , So there's no red waiting time . wait until I/O The program completes the operation ,Event Loop The thread returns the result to the main thread . The main thread calls the preset callback function , Complete the whole task .

Node.js Use the event driven model , When web server Received request , Just turn it off and deal with it , Then go to serve the next web request . When this request is completed , It was put back Processing queues ( Or event queues , Similar to the message thread in the previous slide ), When it reaches the beginning of the queue , This result is returned to the user . This model is very efficient and extensible , because webserver Always accept requests without waiting for any read or write operations .( It's also called non blocking IO Or event driven IO)

nodejs Note more about the event cycle

  1. nodejs Events and event loops

    Catalog brief introduction nodejs The cycle of events in phase Detailed explanation timers pending callbacks idle, prepare poll polling check close callbacks setTi ...

  2. Event Loop The event loop ,GET!

    JS One of the more troublesome problems in is asynchronous events , For example, we often have to wait for the background to return data dom operation , Another example is that we need to set a timer to fulfill specific requirements . In these synchronous and asynchronous events , Asynchronous events must follow synchronous events , But asynchronous events ...

  3. node.js Learning notes ( 3、 ... and )—— The event loop

    To understand the event loop , First, understand event driven programming (Event Driven Programming). It appears in 1960 year . Now , Event driven programming in UI It's used a lot in programming .JavaScript One of the main uses of is with DOM Interaction ...

  4. nodejs The event loop

    1. Only one main thread ,node When you start executing the script , It will initialize the event loop ( Synchronization task , Make asynchronous request , Plan when the timer will take effect , perform promise.nextTick etc. ), This is the cycle of events that hasn't started yet . 2. nodejs each ...

  5. 【 Spreading wisdom Podcast 】Libevent Learning notes ( 3、 ... and ): The event loop

    Catalog 00. Catalog 01. event_base_loop function 02. event_base_dispatch function 03. event_base_loopexit function 04. event_base_l ...

  6. 【nodejs principle & Source appreciation (7)】【 translate 】Node.js The cycle of events in , Timers and process.nextTick

    [ Abstract ] Blog translation on the official website ,nodejs Timer in The sample code is hosted in :http://www.github.com/dashnowords/blogs Original address :https://nodejs.org/en/d ...

  7. 【nodejs principle & Source appreciation (7)】【 translate 】Node.js The cycle of events in , Timers and process.nextTick

    Catalog Event Loop What is it? ? Event Loop Basic explanation Overview of event cycle phases Event loop details timers pending callbacks poll Stage check close callb ...

  8. Browser event loop & nodejs The event loop

    The first 1 piece : How to understand EventLoop—— Macro task and micro task Macro task (MacroTask) introduce stay JS in , Most tasks are performed on the main thread , Common tasks are : Rendering Events User interaction events js Script execution Network request . ...

  9. On nodejs Event cycle mechanism event loop

    nodejs Characteristics nodejs  With event driven and non blocking I/O Characteristics . Event driven means nodejs Treat every task as an event . Non blocking I/O Refer to nodejs encounter I/O When the task , Individual thread processing is scheduled from the thread pool I ...

Random recommendation

  1. nginx install waf protective

    One . install nginx Two . install luajit2.0 3、 ... and . install ngx_devel_kit#wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.1 ...

  2. SELECT Control operation JS Code example

    SELECT Control operation JS Code example 1 Check if there is a check if(objSelect.selectedIndex > -1) { // Explain that } else { // It means that... Is not selected } 2. Dynamically create s ...

  3. Do things for others

    morning , Go to breakfast at the usual time , The dining hall is very open , The employees of the restaurant said that there are very few people today , I said there was a new year's party yesterday , She said today is a holiday , I thought later , What she said is more reasonable . She sees better than I do ! Fortunately, last night, I recorded that I had to search papers for others in the morning ...

  4. WPF: Form top

    1. Set the form TopMost attribute private DispatcherTimer timer; public Window1() { InitializeComponent(); Loaded += n ...

  5. Java Collection Series 02 Collection framework

    java Collection series directory : Java Collection Series 01 General framework Java Collection Series 02 Collection framework Java Collection Series 03 ArrayList Detailed introduction ( The source code parsing ) And use examples Java ...

  6. DoG 、Laplacian、 Image pyramid

    DoG(Difference of Gaussian) DoG (Difference of Gaussian) It is a method of gray image enhancement and corner detection , It's simpler , The proof is more complicated , The details are as follows : Differe ...

  7. ( turn )jquery.validator The rules

      Sign in | register     Collection success determine Collection failed , Please collect it again determine title The title cannot be empty website label Abstract   Open Cancel collection             Share information Pass on PPT/ file Asking questions Blogging Transmission resources ...

  8. C# Several common sorting methods

    1. Bubble sort // Bubble sort public void BubbleSort(int[] list) { int i, j, temp; bool done = false; j = ; while (( ...

  9. 【 Logical loopholes 】 be based on BurpSuite Ultra vires test practical course

    One . What is ultra vires loophole ? How it came into being ? The loophole of ultra vires is Web A common security vulnerability in applications . The threat is that one account can control the entire user data . Of course, these data are limited to the data corresponding to the vulnerability function . The main cause of ultra vires loopholes is that developers ...

  10. [android] Toggle button - Custom control - Drag effect

    rewrite View Of onTouchEvent() Method , Pass it on MotionEvent object call MotionEvent Object's getAction() Method , Get the current action switch Judge the current action The event is Mot ...