Skip to content

Instantly share code, notes, and snippets.

@SuperAL
Created March 26, 2018 07:21
Show Gist options
  • Select an option

  • Save SuperAL/0816369abaf44a52b8564e9f5464ae35 to your computer and use it in GitHub Desktop.

Select an option

Save SuperAL/0816369abaf44a52b8564e9f5464ae35 to your computer and use it in GitHub Desktop.
javascript 实现 sleep 函数
// 链接: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