Created
May 13, 2019 22:21
-
-
Save codexico/c7b47d95650be2b3252c3c12fa1cf5e4 to your computer and use it in GitHub Desktop.
retry function N times with condition in javascript
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
function executeOrRetry(retries, condition, fn, interval) { | |
if ((retries > 0) && condition()) { | |
setTimeout(() => { | |
executeOrRetry(retries--, condition, fn); | |
}, interval); | |
} else { | |
fn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment