JavaScript/sleep:修订间差异
来自康健生活
| 第11行: | 第11行: | ||
同步执行 | 同步执行 | ||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
<syntaxhighlight lang="javascript"> | |||
function sleep (time) { | function sleep (time) { | ||
return new Promise((resolve) => setTimeout(resolve, time)); | return new Promise((resolve) => setTimeout(resolve, time)); | ||
| 第21行: | 第20行: | ||
await sleep(3000); | await sleep(3000); | ||
console.log('Do other things, ' + new Date()); | console.log('Do other things, ' + new Date()); | ||
})();</syntaxhighlight> | })();</syntaxhighlight>|{{consoleout|<pre> | ||
Do some thing, Wed Jun 24 2020 23:42:28 GMT+0800 (中国标准时间) | |||
Promise {<pending>} | |||
VM199:8 Do other things, Wed Jun 24 2020 23:42:31 GMT+0800 (中国标准时间) | |||
</pre>}}}} | |||
{{unknown}} | {{unknown}} | ||