Skip to content

Instantly share code, notes, and snippets.

@ZacSweers
Forked from jerrellmardis/ExponentialBackoff
Last active April 14, 2020 06:51
Show Gist options
  • Save ZacSweers/7902e3a0286774630f4f to your computer and use it in GitHub Desktop.
Save ZacSweers/7902e3a0286774630f4f to your computer and use it in GitHub Desktop.
Exponential Backoff using Rx.retryWhen() I DON'T KNOW WHY THIS HAS HIGH SEO I JUST FORKED IT TO SAVE A COPY
// retries up to 3 times while exponentially backing off with each retry
.retryWhen(errors ->
errors
.zipWith(
Observable.range(1, MAX_RETRIES), (n, i) -> i
)
.flatMap(
retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS)
)
)
@tuchangwei
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment