当前位置:网站首页>Understanding of event queue, micro task and macro task and interview questions
Understanding of event queue, micro task and macro task and interview questions
2022-06-30 19:31:00 【Supreme and peerless】
An event queue is a data structure , Can store tasks to be performed . It matches the queue " fifo " Characteristics .
Not only one queue is maintained in the event loop , In fact, there are two queues :
- Macro task queue (macrotask queue): ajax、setTimeout、setInterval、DOM monitor 、UI Rendering etc.
- Micro task queue (microtask queue): Promise Of then Callback 、Mutation Observer API、queueMicrotask()
What is the priority of the event loop for the two queues ?
1.main script The code in takes precedence ;
2. stay Before executing any macro task ( It's not a queue , It's a macro task ), First of all View micro task queue Is there a task to perform
That is, before the macro task is executed , You must ensure that the macro task queue is empty ;
If it's not empty , Then priority is given to the tasks in the micro task queue ( Callback );
Promise Interview question one
setTimeout(function(){
console.log("setTimeout1");
new Promise(function (resolve){
resolve()
}).then(function(){
new Promise(function(resolve){
resolve()
}).then(function(){
console.log("then4");
})
console.log("then2");
})
})
new Promise(function(resolve){
console.log("promise1");
resolve()
}).then(function(){
console.log("then1");
})
setTimeout(function(){
console.log("setTimeout2");
})
console.log(2);
queueMicrotask(()=> {
console.log("queueMicrotask");
})
new Promise(function(resolve){
resolve()
}).then(function() {
console.log("then3");
})promise async await Interview question two
async function async1() {
console.log("async1 start");
await async2()
console.log("async1 end");
}
async function async2() {
console.log("async2");
}
console.log("script start");
setTimeout(function(){
console.log("setTimeout")
}, 0)
async1()
new Promise( function (resolve) {
console.log("promise");
resolve()
}).then(function(){
console.log("promise2");
})
console.log("script end");边栏推荐
- ArcGIS无插件加载(无偏移)天地图
- Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
- Task01: getting to know database and SQL (Note 1)
- Cobbler轻松上手
- js 字符串截取方法汇总
- Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
- 连接实验室服务器
- 阿里天池SQL训练营学习笔记5
- Kalman filter -- Derivation from Gaussian fusion
- Opencv data type code table dtype
猜你喜欢

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

Pyth Solana is a bridge connecting reality on the chain

美国服务器租用和托管服务哪个好?

如何使用物联网低代码平台进行服务管理?

Swin-transformer --relative positional Bias

Promise从认识到使用

德国AgBB VoC有害物质测试

BeanUtils.copyProperties() 对比 mapstruct

Kalman filter -- Derivation from Gaussian fusion

Entry node of link in linked list - linked list topic
随机推荐
Practical application of "experience" crawler in work "theory"
力扣------统计包含给定前缀的字符串
Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
Pyth-Solana链上联通现实的桥梁
Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
[JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享
German agbb VOC hazardous substances test
阿里天池SQL训练营学习笔记5
Memory Limit Exceeded
开发那些事儿:如何在视频中添加文字水印?
mysql函数获取全路径
【DesignMode】工厂模式 (factory pattern)
嵌入式软件开发新趋势:DevOps
com.alibaba.fastjson.JSONObject # toJSONString 消除循环引用
Nodejs 安装与介绍
手机炒股开户安全嘛!?
如何利用 xUnit 框架对测试用例进行维护?
MySQL 索引测试
MySQL recursion
法国A+ 法国VOC标签最高环保级别