AJAX implementation in single-threaded Javascript

How are AJAX requests executed asynchronously if Javascript is not multithreaded?

Is it a specific implementation browser?

+6
source share
1 answer

The browser execution model is based on the concept of an event loop. There is only one stream maintenance service (slight simplification). When an event occurs, handlers are called sequentially.

Ajax is just a mechanism that triggers certain events. Setting up an HTTP request is synchronous, but just setting it up. The browser responds to network communications presenting return data from the server by triggering events when this happens.

Modern browsers are somewhat more complicated in that each window can have its own process (or some other "thread" at the system level, to be common). In addition, the new "Web Worker" feature allows you to simultaneously run separate stream compartments.

+8
source

Source: https://habr.com/ru/post/927193/


All Articles