Created
April 3, 2019 16:41
-
-
Save ashleywxwx/d2cd5076e8afae755d6f8afc2de58bda to your computer and use it in GitHub Desktop.
Retries, but with an exponential backoff
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
| const retryWithBackoff = (eventuallyTrue, callback, retries = 10, msDelay = 100) => { | |
| if (eventuallyTrue()) { | |
| callback(); | |
| } else if (retries > 0) { | |
| setTimeout(() => retryWithBackoff(eventuallyTrue, --retries, msDelay * 2, callback), msDelay); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment