Created
February 13, 2017 12:27
-
-
Save hcl1687/0d825d3f6128fda5e605b97a5fffbd03 to your computer and use it in GitHub Desktop.
js sleep function
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
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function demo() { | |
console.log('Taking a break...'); | |
await sleep(2000); | |
console.log('Two second later'); | |
} | |
demo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment