当前位置:网站首页>Code execution sequence with and without resolve in promise
Code execution sequence with and without resolve in promise
2022-07-02 06:46:00 【The health of the bright moon in Qin Dynasty】
Please write the output order of the following code :
Example 1:
console.log('script start')
new Promise(function(resolve) {
console.log('promise')
resolve()
console.log('promise after resolve')
}).then(function() {
console.log('promise then')
})
console.log('script end')
Example 2:
console.log('script start')
await new Promise(function(resolve) {
console.log('promise')
resolve()
console.log('promise after resolve')
}).then(function() {
console.log('promise then')
})
console.log('script end')
Example 3:
console.log('script start')
await new Promise(function(resolve) {
console.log('promise')
return resolve()
console.log('promise after resolve')
}).then(function() {
console.log('promise then')
})
console.log('script end')
Example 4:
console.log('run begin')
run()
console.log('run end')
async function run() {
console.log(0)
for (let i = 1; i <= 5; i++) {
await func1()
}
}
async function func1() {
console.log('func1 begin')
await new Promise((resolve, reject) => {
console.log('promise')
})
console.log('func1 end')
}
Example 5:
console.log('run begin')
run()
console.log('run end')
async function run() {
console.log(0)
for (let i = 1; i <= 5; i++) {
await func1()
}
}
async function func1() {
console.log('func1 begin')
await new Promise((resolve, reject) => {
console.log('promise')
resolve()
})
console.log('func1 end')
}
Extended reading : Together setTimeout async promise Thoughts on the written examination questions of execution order
边栏推荐
- ctf-web之练习赛
- Win10: add or delete boot items, and add user-defined boot files to boot items
- Redis——大Key问题
- Kali latest update Guide
- Detailed definition of tensorrt data format
- Summary of advertisement business bug replay
- Virtualenv and pipenv installation
- 重载全局和成员new/delete
- Vector types and variables built in CUDA
- Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件
猜你喜欢

CTF three count

Detailed definition of tensorrt data format

pytest(2) mark功能

Distributed transactions: the final consistency scheme of reliable messages

Redis - cluster data distribution algorithm & hash slot

table 组件指定列合并行方法

CTF web practice competition

Win10: add or delete boot items, and add user-defined boot files to boot items

Redis——热点key问题

The default Google browser cannot open the link (clicking the hyperlink does not respond)
随机推荐
pytest(2) mark功能
qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
Fe - wechat applet - Bluetooth ble development research and use
浏览器滚动加载更多实现
Fe - eggjs combined with typeorm cannot connect to the database
Pytest (2) mark function
Win10: add or delete boot items, and add user-defined boot files to boot items
sprintf_ How to use s
Cglib agent - Code enhancement test
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
No process runs when querying GPU, but the video memory is occupied
Browser scrolling for more implementations
After reading useful blogs
Name six schemes to realize delayed messages at one go
unittest.TextTestRunner不生成txt测试报告
selenium+msedgedriver+edge浏览器安装驱动的坑
Summary of advertisement business bug replay
Improve user experience defensive programming
Alibaba cloud MFA binding Chrome browser
底层机制Mvcc