Created
December 14, 2019 12:11
-
-
Save UniBreakfast/3c6610576c4d0e140c3b6efbece23f16 to your computer and use it in GitHub Desktop.
To insert arbitrary delay in an async function
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
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