Skip to content

Instantly share code, notes, and snippets.

@ashleywxwx
Created April 3, 2019 16:41
Show Gist options
  • Select an option

  • Save ashleywxwx/d2cd5076e8afae755d6f8afc2de58bda to your computer and use it in GitHub Desktop.

Select an option

Save ashleywxwx/d2cd5076e8afae755d6f8afc2de58bda to your computer and use it in GitHub Desktop.
Retries, but with an exponential backoff
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