Created
March 25, 2022 14:58
-
-
Save RyanNutt/996919982ac4df7f861472edf98567cb to your computer and use it in GitHub Desktop.
JavaScript sleep methods from https://stackoverflow.com/a/39914235/1561431
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
// As a function | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// One liner | |
await new Promise(r => setTimeout(r, 2000)); | |
// Or | |
const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
await sleep(<duration>); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment