当前位置:网站首页>Promise中有resolve和无resolve的代码执行顺序
Promise中有resolve和无resolve的代码执行顺序
2022-07-02 06:22:00 【秦时明月之安康】
请写出下面代码的输出顺序:
示例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')
示例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')
示例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')
示例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')
}
示例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')
}
边栏推荐
猜你喜欢
Find the highest value of the current element Z-index of the page
IDEA公布全新默认UI,太清爽了(内含申请链接)
Linux MySQL 5.6.51 Community Generic 安装教程
Redis——热点key问题
js中对于返回Promise对象的语句如何try catch
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
CUDA中的Warp Shuffle
js中map和forEach的用法
ctf-web之练习赛
CUDA中的线程层次
随机推荐
Codeforces Round #797 (Div. 3) A—E
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
2020-9-23 QT的定时器Qtimer类的使用。
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
CUDA中的Warp matrix functions
Linked list (linear structure)
pytest(2) mark功能
Fe - wechat applet - Bluetooth ble development research and use
Eggjs -typeorm 之 TreeEntity 实战
ZZQ的博客目录--更新于20210601
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
FE - weex 开发 之 使用 weex-ui 组件与配置使用
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
(第一百篇BLOG)写于博士二年级结束-20200818
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
js中正则表达式的使用
部署api_automation_test过程中遇到的问题
Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题