码迷,mamicode.com
首页 > 其他好文 > 详细

es7 async await 异步

时间:2018-11-10 16:46:21      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:timeout   OLE   wait   执行   ons   time   res   div   cti   

created 里面
  
let _this = this;
async function asyncAwaitFn1() {
  return await new Promise((resolve, reject) => {
    _this.a(resolve);
  })
}
async function asyncAwaitFn2() {
  return await new Promise((resolve, reject) => {
    _this.b(resolve);
  })
}
const serialFn = async () => { //串行执行
  console.time(‘serialFn‘)
  await asyncAwaitFn1();
  await asyncAwaitFn2();
  console.timeEnd(‘serialFn‘)
}

serialFn();
-----------------------------------------------------------------------------------------------------------------------------
methods
  a(resolve){
    setTimeout(() => {
    console.log(1)
    if(resolve){
      resolve();
    }
    }, 3000);
  },
  b(resolve){
    setTimeout(() => {
      console.log(2)
      if(resolve){
        resolve();
      }
    }, 1000);
  },

es7 async await 异步

标签:timeout   OLE   wait   执行   ons   time   res   div   cti   

原文地址:https://www.cnblogs.com/qiudongjie/p/9939669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!