Created
March 26, 2018 07:21
-
-
Save SuperAL/0816369abaf44a52b8564e9f5464ae35 to your computer and use it in GitHub Desktop.
javascript 实现 sleep 函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 链接:https://www.zhihu.com/question/31636244/answer/52835780 | |
| // 来源:知乎 | |
| async function test() { | |
| console.log('Hello') | |
| await sleep(1000) | |
| console.log('world!') | |
| } | |
| function sleep(ms) { | |
| return new Promise(resolve => setTimeout(resolve, ms)) | |
| } | |
| test() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment