当前位置:网站首页>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')
}
边栏推荐
- Detailed definition of tensorrt data format
- FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
- js中map和forEach的用法
- 底层机制Mvcc
- Find the highest value of the current element Z-index of the page
- [self cultivation of programmers] - Reflection on job hunting Part II
- 压力测试修改解决方案
- Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
- The intern left a big hole when he ran away and made two online problems, which made me miserable
- Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
猜你喜欢

Fe - wechat applet - Bluetooth ble development research and use

分布式事务 :可靠消息最终一致性方案

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

Introduce two automatic code generators to help improve work efficiency

查询GPU时无进程运行,但是显存却被占用了

Redis - cluster data distribution algorithm & hash slot

Redis - grande question clé

Solution to the black screen of win computer screenshot

蚂蚁集团g6初探

Summary of advertisement business bug replay
随机推荐
ShardingSphere-JDBC篇
js中map和forEach的用法
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
Redis——Cluster数据分布算法&哈希槽
Blog directory of zzq -- updated on 20210601
ctf-web之练习赛
automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
Distributed transactions: the final consistency scheme of reliable messages
CUDA中的Warp Shuffle
Warp shuffle in CUDA
CUDA用户对象
Redis——大Key问题
Vector types and variables built in CUDA
Dynamic global memory allocation and operation in CUDA
蚂蚁集团g6初探
Sentinel规则持久化到Nacos
Redis - hot key issues
Learn about various joins in SQL and their differences
阿里云MFA绑定Chrome浏览器
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content