Created
July 21, 2017 15:44
-
-
Save fernandocanizo/732523e50d819559365dffe686dec881 to your computer and use it in GitHub Desktop.
A proper sleep function for Javascript ES2017
This file contains 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
// Taken from | |
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep/39914235#39914235 | |
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