Skip to content

Instantly share code, notes, and snippets.

@jerrellmardis
Last active June 3, 2019 13:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jerrellmardis/536ee5ebd8d33d3bf595 to your computer and use it in GitHub Desktop.
Save jerrellmardis/536ee5ebd8d33d3bf595 to your computer and use it in GitHub Desktop.
Exponential Backoff using Rx.retryWhen()
// 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)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment