Created
January 5, 2020 16:45
-
-
Save Nithanaroy/f0264c6bed46a8793ee3b744b5dfcd22 to your computer and use it in GitHub Desktop.
Snippet that achieves Python's sleep
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
async function main() { | |
console.log(`Start: ${performance.now()}`); | |
await sleep(2000); | |
console.log(`End: ${performance.now()}`); | |
} |
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 sleep(timeInMs) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve("Time up!"); | |
}, timeInMs); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment