Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fernandocanizo/732523e50d819559365dffe686dec881 to your computer and use it in GitHub Desktop.
Save fernandocanizo/732523e50d819559365dffe686dec881 to your computer and use it in GitHub Desktop.
A proper sleep function for Javascript ES2017
// 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