Created
May 4, 2017 13:43
-
-
Save ThomasG77/23d10f9394b0d00f4d867069f84d2ba1 to your computer and use it in GitHub Desktop.
Sleep function in JavaScript (need node v7.10+, borrowed from https://twitter.com/samccone/status/859777976199659521)
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
async function sleep (dur) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), dur); | |
}); | |
} | |
async function yay () { | |
console.log('i am sleepy'); | |
await sleep(5000); | |
console.log('i need more sleep'); | |
await sleep(10000); | |
console.log('all rested'); | |
} | |
yay(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment