当前位置:网站首页>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
边栏推荐
- 提高用户体验 防御性编程
- 2020-9-23 QT的定时器Qtimer类的使用。
- (第一百篇BLOG)写于博士二年级结束-20200818
- web自动化切换窗口时报错“list“ object is not callable
- Common function writing method and set get writing method for calculating attributes
- Idea announced a new default UI, which is too refreshing (including the application link)
- js中map和forEach的用法
- js中正则表达式的使用
- Distributed transactions: the final consistency scheme of reliable messages
- 如何调试微信内置浏览器应用(企业号、公众号、订阅号)
猜你喜欢

Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *

AWD learning

pytest(1) 用例收集规则

A preliminary study on ant group G6

Latex compilation error I found no \bibstyle &\bibdata &\citation command

Sublime text configuring PHP compilation environment

代码技巧——Controller参数注解@RequestParam

Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)

The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem

Blog directory of zzq -- updated on 20210601
随机推荐
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
table 组件指定列合并行方法
After reading useful blogs
kali最新更新指南
PgSQL learning notes
Common function writing method and set get writing method for calculating attributes
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Log (common log framework)
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
js中正则表达式的使用
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
ctf三计
如何调试微信内置浏览器应用(企业号、公众号、订阅号)
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
selenium的web自动化中常用的js-修改元素属性翻页
Latex error: the font size command \normalsize is not defined problem solved
Deployment API_ automation_ Problems encountered during test
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
Latex compilation error I found no \bibstyle &\bibdata &\citation command