mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-28 21:32:20 +00:00
Merge pull request #869 from PanJiaChen/gh-pages
docs(async): refine sleep
This commit is contained in:
commit
5a773c8c81
@ -253,8 +253,8 @@ class Sleep {
|
|||||||
这个例子还演示了如何实现休眠效果。JavaScript 一直没有休眠的语法,但是借助`await`命令就可以让程序停顿指定的时间。下面给出了一个简化的`sleep`实现。
|
这个例子还演示了如何实现休眠效果。JavaScript 一直没有休眠的语法,但是借助`await`命令就可以让程序停顿指定的时间。下面给出了一个简化的`sleep`实现。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
async function sleep(interval) {
|
function sleep(interval) {
|
||||||
await new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(resolve, interval);
|
setTimeout(resolve, interval);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user