当前位置:网站首页>What is asynchronous operation
What is asynchronous operation
2022-07-26 09:19:00 【Xiaomeng new admission】
1. Background introduction
Synchronization means that only one task can be completed at a time . If there are multiple tasks , You have to line up , The first task is finished , Do the next task , And so on .
Asynchrony means that each task has one or more callback functions (callback), After the end of the previous mission , Not to perform the latter task , Instead, execute the callback function , The latter task is executed before the end of the previous task , So the execution order of the program is inconsistent with the order of the tasks 、 Asynchronous .
2. Knowledge analysis
First js It's a single-threaded language , That is, you can only do one thing at a time . that Js How to implement asynchronous , Isn't asynchrony and single thread self contradictory ? Actually , Single thread and asynchrony really can't be features of a language at the same time .js Chose to become a single threaded language , So it cannot be asynchronous by itself , but js The host environment of ( For example, browser ,Node) It's multi-threaded , The host environment in some way ( Event driven , I'll talk about ) bring js With asynchronous properties .
Browser kernel is multithreaded , They work together under kernel control to keep up with each other , A browser implements at least three resident threads :javascript Engine threads ,UI Rendering thread , Browser event trigger thread .
1.javascript Engine threads are based on event driven single thread execution ,JS The engine is waiting for the task in the task queue , And then deal with it , There is only one browser at any time JS The thread is running JS Program .
2.UI The rendering thread is responsible for rendering the browser interface , When the interface needs to be redrawn (Repaint) Or cause reflux due to an operation (reflow) when , The thread will execute . But we need to pay attention UI Rendering thread and JS Engines are mutually exclusive , When JS Engine execution time UI Thread will be suspended ,UI Updates will be saved in a queue medium to JS Execute immediately when the engine is idle .
3. Event trigger thread , When an event is triggered, the thread will add the event to the end of the queue to be processed , wait for JS Engine handling . These events can come from JavaScript The code block currently executed by the engine is as follows setTimeOut、 Other threads from the browser kernel, such as mouse click 、AJAX Asynchronous request, etc , But because of JS All these events have to be queued JS Engine processing .
3. common problem And Solution
ajax What does the browser do when sending asynchronous requests ?
1.Js Created a ajax request
2. Open another browser ajax Engine threads , perform ajax request
3. After the execution gets the response, put the callback function into the task queue .
4.Js Execute the callback function in the task queue .
What are the common asynchronous callback functions ?
1, Click time ,
2, Timer ,
3,AJAX request .
边栏推荐
- Order based evaluation index (especially for recommendation system and multi label learning)
- Windows通过命令备份数据库到本地
- The child and binary tree- open root inversion of polynomials
- Summary of common activation functions for deep learning
- 谷粒学院的全部学习源码
- 十大蓝筹NFT近半年数据横向对比
- Codeworks DP collection
- Local cache
- Pat grade a A1034 head of a gang
- Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
猜你喜欢

Canal 的学习笔记

2022化工自动化控制仪表操作证考试题模拟考试平台操作

Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world

【Mysql】Mysql锁详解(三)

Original root and NTT 5000 word explanation

围棋智能机器人阿法狗,阿尔法狗机器人围棋

Mysql事务

十大蓝筹NFT近半年数据横向对比

Object 的Wait Notify NotifyAll 源码解析

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
随机推荐
2022 chemical automation control instrument operation certificate test question simulation test platform operation
JS - DataTables control on the number of displays per page
When you click input, the border is not displayed!
围棋智能机器人阿法狗,阿尔法狗机器人围棋
基于序的评价指标 (特别针对推荐系统和多标签学习)
JS - DataTables 关于每页显示数的控制
Server memory failure prediction can actually do this!
【Mysql】redo log,undo log 和binlog详解(四)
多层嵌套后的 Fragment 懒加载实现
【Mysql】Mysql锁详解(三)
LeetCode三数之和问题
分布式跟踪系统选型与实践
Order based evaluation index (especially for recommendation system and multi label learning)
839. Simulation reactor
CF1481C Fence Painting
“could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32” 问题处理
【线上死锁分析】由index_merge引发的死锁事件
Redis principle and use - Basic Features
【Flutter -- 布局】Align、Center、Padding 使用详解
Force button list question