Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Created May 4, 2017 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/23d10f9394b0d00f4d867069f84d2ba1 to your computer and use it in GitHub Desktop.
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)
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