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());
})();

你可能感兴趣的:(JavaScript 利用 async await 实现 sleep 效果)