In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the principle of asynchronous transmission by JavaScript". In daily operation, I believe that many people have doubts about the principle of asynchronous transmission by JavaScript. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the principle of asynchronous transmission by JavaScript?" Next, please follow the editor to study!
1. Browser
In our development, JavaScript in the browser can implement two more important interfaces, which are timers and ajax requests.
Timer:
For the timer, when it is executed, our browser will count the execution timing, and push the event to our JavaScript event after the timing event is triggered, and the time event will be executed only after the JavaScript main thread synchronization is completed, so the JavaScript timer is not triggered on time.
Ajax:
Then our Ajax request is the same as our timer. They also delegate the browser to perform the task. In Ajax, it is because the http request thread in the browser initiates the service request, completes the event after receiving the request, and then pushes the callback function to our event queue to wait.
II. Node JS terminal
The asynchronous implementation of Node JS is different from the browser implementation. Libuv in Node JS provides us with a lot of capabilities, including: cross-platform, thread pool, event pool, asynchronous Imax O, and so on. Not only that, Libuv also provides a unified API call for the upper layer of Node.js, which allows us not to consider the gap between platforms when using it, but also hides the underlying implementation. For Libuv, it is asynchronous and time-driven, so when we send the request for the Icano operation to Libuv, we will open the thread to execute our Icano call. After that, the JavaScript is passed to us for final processing.
Initiate an Icano call:
1. What we are using is to let users call the NodeJS core module through Javascript code and pass parameters and callbacks into the core module.
2. In NodeJS, we need to encapsulate the incoming parameters and callback into a request object through the core module.
3. Push the request object into the I / O thread pool and wait for J.
4. The asynchronous call initiated by avascript ends, and the Javascript thread continues to perform subsequent operations.
Execute callback:
1. After the asynchronous task is completed, the result will be stored on the result attribute of the request object, and the operation completion notification will be issued.
2. Each event loop will check whether there is a completed Ipicuro operation in the Icano thread pool, and if so, add the request event to the Icano observer queue (event queue), and then treat it as an event.
3. When handling the Javascript O Observer event, the callback function encapsulated in the request object will be taken out and the callback parameter will be passed into execution to achieve the purpose of Javascript callback.
At this point, the study of "what is the principle of asynchronous transmission by JavaScript" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.