Created
November 12, 2020 03:40
-
-
Save dxrcy/6b440911453ae197aaf8b9c04ff2a3d3 to your computer and use it in GitHub Desktop.
Sleep function for async javascript
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
function sleep(time) { | |
return new Promise(resolve => { | |
setTimeout(resolve, time * 1000); | |
}); | |
} | |
(async()=>{ | |
console.log("Start"); | |
await sleep(1); | |
console.log("1 second later"); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment