JavaScript 利用 async await 实现 sleep 效果

const sleep = (timeountMS) => new Promise((resolve) => {
  setTimeout(resolve, timeountMS);
});

(async () => {
  console.log('11111111, ' + new Date());
  await sleep(2000);
  console.log('22222222, ' + new Date());
  await sleep(2000);
  console.log('33333333, ' + new Date());
})();
posted @ 2019-02-21 10:23  Mr.曹  阅读(5174)  评论(1编辑  收藏  举报