Created
July 5, 2021 11:18
-
-
Save itaditya/583451ed4db6ac4cfec418e4343a5b52 to your computer and use it in GitHub Desktop.
Easy way to delay promise resolving
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
function sleep(duration, shouldFail) { | |
return new Promise((resolve, reject) => { | |
const cb = shouldFail ? reject : resolve; | |
setTimeout(() => cb(), duration); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment