其他分享
首页 > 其他分享> > es6 async await

es6 async await

作者:互联网

const getData = () => new Promise(resolve => setTimeout(() => resolve("data"), 1000))

async function test() {
  const data = await getData()
  console.log('data: ', data);
  const data2 = await getData()
  console.log('data2: ', data2);
  return 'success'
}

// 这样的一个函数 应该再1秒后打印data 再过一秒打印data2 最后打印success
test().then(res => console.log(res))

  

标签:es6,const,log,await,async,getData,data,data2
来源: https://www.cnblogs.com/tonnytong/p/14844872.html