JavaScript/sleep:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 引用 == == 模拟 == <syntaxhighlight lang="javascript"> function sleep (time) { return new Promise((resolve) => setTimeout(resolve, time)); } sleep(500).the…”
 
Kangkk​(留言 | 贡献)
第9行: 第9行:
   // ...
   // ...
})</syntaxhighlight>
})</syntaxhighlight>
同步执行
<syntaxhighlight lang="javascript">
function sleep (time) {
  return new Promise((resolve) => setTimeout(resolve, time));
}
(async function() {
  console.log('Do some thing, ' + new Date());
  await sleep(3000);
  console.log('Do other things, ' + new Date());
})();</syntaxhighlight>
{{unknown}}