当前位置:网站首页>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
边栏推荐
- Render minecraft scenes into real scenes using NVIDIA GPU
- Fe - use of weex development weex UI components and configuration use
- pytest(1) 用例收集规则
- Win10: add or delete boot items, and add user-defined boot files to boot items
- Sublime Text 配置php编译环境
- pytest(2) mark功能
- Deployment API_ automation_ Problems encountered during test
- Function execution space specifier in CUDA
- Redis - hot key issues
- Linux MySQL 5.6.51 Community Generic 安装教程
猜你喜欢
No process runs when querying GPU, but the video memory is occupied
Win电脑截图黑屏解决办法
Sentry搭建和使用
Warp shuffle in CUDA
PgSQL learning notes
Name six schemes to realize delayed messages at one go
Latex在VSCODE中编译中文,使用中文路径问题解决
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
Latex warning: citation "*****" on page y undefined on input line*
AWD learning
随机推荐
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)
pytest(1) 用例收集规则
Vscode installation, latex environment, parameter configuration, common problem solving
Virtualenv and pipenv installation
PIP install
DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
提高用户体验 防御性编程
Latex warning: citation "*****" on page y undefined on input line*
web自动中利用win32上传附件
sprintf_s的使用方法
Uploading attachments using Win32 in Web Automation
Asynchronous data copy in CUDA
Vector types and variables built in CUDA
Storage space modifier in CUDA
Warp matrix functions in CUDA
Solution to the black screen of win computer screenshot
table 组件指定列合并行方法
CTF three count
看完有用的blog
unittest. Texttestrunner does not generate TXT test reports