Last active
February 22, 2018 13:45
-
-
Save santhosh17s/ecd7807e0940b594d93fbc90a6794c14 to your computer and use it in GitHub Desktop.
Sleep in JS using Promises, async, wait
This file contains hidden or 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
| 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