Event Loop Personal Understanding

Source: Internet
Author: User

The JavaScript engine is a single-threaded procedure that performs synchronous operations down sequentially and executes an asynchronous operation using the event loop model.

When the JS engine thread encounters an asynchronous operation, it gives the asynchronous operation to the corresponding observer,

Asynchronous operations include:

Dom Event Click,mousedown, etc.
Timer Settimeout,setinterval
IO network io, file io, other io (localstorage,cookie), IO operations will be handed to the corresponding thread pool to execute

The Observer observes the state of the asynchronous operation and, when the asynchronous operation completes, encapsulates the corresponding asynchronous information (including callback, etc.) into an event-push event queue.

The JS engine thread continuously polls the event queue, reads the event according to the FIFO principle, if there is an event, takes out, executes its callback, and executes a callback process called a loop (Tick),

Execution completes and enters the next loop (Nexttick).

If the event queue is empty, the JS engine executes an empty loop.

In the browser, the JS engine and the GUI engine is mutually exclusive, that is, the JS engine will block the UI rendering, when the JS synchronization continues to execute, the UI will not be updated, will be stuck in the state.

Event Loop Personal Understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.