当前位置:网站首页>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')
}
边栏推荐
- Dynamic global memory allocation and operation in CUDA
- Data science [9]: SVD (2)
- AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
- ShardingSphere-JDBC篇
- Redis——大Key问题
- 实现strStr() II
- Idea announced a new default UI, which is too refreshing (including the application link)
- CUDA中的Warp matrix functions
- unittest.TextTestRunner不生成txt测试报告
- Pytest (2) mark function
猜你喜欢

pytest(1) 用例收集规则
![Data science [9]: SVD (2)](/img/2c/f1a8c3ff34ff3f3cc6e26157a32bfd.png)
Data science [9]: SVD (2)

由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决

VSCODE 安装LATEX环境,参数配置,常见问题解决

Find the highest value of the current element Z-index of the page

There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)

Redis - cluster data distribution algorithm & hash slot

IDEA公布全新默认UI,太清爽了(内含申请链接)

最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)

Linked list (linear structure)
随机推荐
pytest(2) mark功能
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
Function execution space specifier in CUDA
Codeforces Round #797 (Div. 3) A—E
20210306转载如何使TextEdit有背景图片
默认google浏览器打不开链接(点击超链接没有反应)
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
Self cultivation of programmers - Reflection on job hunting
Find the highest value of the current element Z-index of the page
Log (common log framework)
Redis——大Key問題
阿里云MFA绑定Chrome浏览器
利用NVIDIA GPU将Minecraft场景渲染成真实场景
一口气说出 6 种实现延时消息的方案
Code skills - Controller Parameter annotation @requestparam
Flask-Migrate 检测不到db.string() 等长度变化
CUDA与Direct3D 一致性
Golang -- map capacity expansion mechanism (including source code)
Fe - eggjs combined with typeorm cannot connect to the database