当前位置:网站首页>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
边栏推荐
- Utilisation de la carte et de foreach dans JS
- Latex compiles Chinese in vscode and solves the problem of using Chinese path
- 重载全局和成员new/delete
- pytest(1) 用例收集规则
- Dynamic global memory allocation and operation in CUDA
- 底层机制Mvcc
- 浏览器滚动加载更多实现
- Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
- ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
- Thread hierarchy in CUDA
猜你喜欢
js中正则表达式的使用
Redis——大Key问题
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
实现strStr() II
Sentinel rules persist to Nacos
Thread hierarchy in CUDA
20201002 vs 2019 qt5.14 developed program packaging
默认google浏览器打不开链接(点击超链接没有反应)
Redis——热点key问题
随机推荐
Summary of advertisement business bug replay
Functions of tensorrt
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
Latex warning: citation "*****" on page y undefined on input line*
(the 100th blog) written at the end of the second year of doctor's degree -20200818
Selenium+msedgedriver+edge browser installation driver pit
sprintf_s的使用方法
代码技巧——Controller参数注解@RequestParam
Latex compiles Chinese in vscode and solves the problem of using Chinese path
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
CUDA and Direct3D consistency
Self cultivation of programmers - Reflection on job hunting
20201002 vs 2019 qt5.14 developed program packaging
Pytest (1) case collection rules
默认google浏览器打不开链接(点击超链接没有反应)
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
自学table au
浏览器滚动加载更多实现
Log (common log framework)