Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Created March 25, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanNutt/996919982ac4df7f861472edf98567cb to your computer and use it in GitHub Desktop.
Save RyanNutt/996919982ac4df7f861472edf98567cb to your computer and use it in GitHub Desktop.
JavaScript sleep methods from https://stackoverflow.com/a/39914235/1561431
// 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