Skip to content

Instantly share code, notes, and snippets.

@UniBreakfast
Created December 14, 2019 12:11
Show Gist options
  • Save UniBreakfast/3c6610576c4d0e140c3b6efbece23f16 to your computer and use it in GitHub Desktop.
Save UniBreakfast/3c6610576c4d0e140c3b6efbece23f16 to your computer and use it in GitHub Desktop.
To insert arbitrary delay in an async function
const sleep = time => new Promise(wakeUp => setTimeout(wakeUp, time))
// ...
await sleep(2000)
// or simply
await new Promise(go => setTimeout(go, 2000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment