当前位置:网站首页>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");边栏推荐
- Configure server environment
- com. alibaba. fastjson. Jsonobject tojsonstring eliminate circular reference
- Go Redis连接池
- Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
- Pyth-Solana链上联通现实的桥梁
- Pyth Solana is a bridge connecting reality on the chain
- Development: how to install offline MySQL in Linux system?
- MySQL recursion
- Memory Limit Exceeded
- Cobbler轻松上手
猜你喜欢

Nodejs installation and introduction

Connect to lab server

【UML】UML类图

Influence and requirements of different manufacturing processes on the pad on PCB

熵-条件熵-联合熵-互信息-交叉熵

项目配置了eslint,编辑器没有关闭eslint功能的情况下,eslint没有生效

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
![20220528 [talk about fake chips] those who are greedy for cheap often suffer heavy losses. Take stock of those fake memory cards and solid state drives](/img/96/8e195536127b90d4eec54294371cad.png)
20220528 [talk about fake chips] those who are greedy for cheap often suffer heavy losses. Take stock of those fake memory cards and solid state drives

ArcGIS无插件加载(无偏移)天地图

微信小程序快速入门 --项目介绍
随机推荐
Lenovo Yoga 27 2022, full upgrade of super configuration
nats集群部署
新版EasyGBS如何配置WebRTC视频流格式播放?
嵌入式软件开发新趋势:DevOps
不同制造工艺对PCB上的焊盘的影响和要求
torch. roll
Year after year, why is breaking the data island still the primary task of enterprise development
Mipi protocol in RFFE
How to use the low code platform of the Internet of things for service management?
MySQL download and installation tutorial
20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
BeanUtils.copyProperties() 对比 mapstruct
4个技巧告诉你,如何使用SMS促进业务销售?
go之web框架 iris
Trust configuring domestic sources
Go语言学习教程(十)
Browser window switch activation event visibilitychange
开发那些事儿:Linux系统中如何安装离线版本MySQL?
JVM常见问题
Development: how to install offline MySQL in Linux system?