Skip to content

Instantly share code, notes, and snippets.

@santhosh17s
Last active February 22, 2018 13:45
Show Gist options
  • Select an option

  • Save santhosh17s/ecd7807e0940b594d93fbc90a6794c14 to your computer and use it in GitHub Desktop.

Select an option

Save santhosh17s/ecd7807e0940b594d93fbc90a6794c14 to your computer and use it in GitHub Desktop.
Sleep in JS using Promises, async, wait
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function sleepWork(){
console.log("I'm going to sleep");
await sleep(100);
console.log("I wake up");
}
sleepWork();
//OUTPUT
//I'm going to sleep
// Promise {<pending>}__proto__: Promise[[PromiseStatus]]: "resolved"[[PromiseValue]]: undefined
//I wake up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment