Created
March 19, 2020 02:05
-
-
Save daltonmenezes/7a5c8824e17a621d900bf4f4f0018f64 to your computer and use it in GitHub Desktop.
A delay/sleep function for javascript
This file contains 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 delay(time) { | |
return new Promise(resolve => | |
setTimeout(resolve, time) | |
) | |
} | |
(async () => { | |
await delay(1000) | |
console.log('It takes 1 second to be executed.') | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment