首页 > 其他 > 详细

promise aync await timeout 执行顺序

时间:2019-11-05 16:00:43      阅读:85      评论:0      收藏:0      [点我收藏+]
async function async1(){
  console.log(‘async1 start‘)
  await async2()
  console.log(‘async1 end‘)
}
async function async2(){
  console.log(‘async2‘)
}
console.log(‘script start‘)
setTimeout(function(){
  console.log(‘setTimeout‘) 
},0)  
async1();
new Promise(function(resolve){
  console.log(‘promise1‘)
  resolve();
}).then(function(){
  console.log(‘promise2‘)
})
console.log(‘script end‘)
script start
async1 start
async2
promise1
script end
promise2
async1 end
setTimeout

顺序:1.同步的 谁在前先执行谁 2.异步的 then > await之后 > timeout


promise aync await timeout 执行顺序

原文:https://www.cnblogs.com/tutao1995/p/11798878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!