Skip to content

Instantly share code, notes, and snippets.

@djensen47
Created July 14, 2015 07:31
Show Gist options
  • Save djensen47/726b5883aa139f6f6323 to your computer and use it in GitHub Desktop.
Save djensen47/726b5883aa139f6f6323 to your computer and use it in GitHub Desktop.
RxJava retryWith example
// slide 75 of this: http://www.slideshare.net/Couchbase/reactive-programmingrxjavaefficientdata-benchristensenmichaelnitschinger
Observable.
.defer(() -> bucket.get("id")) //create new
.retryWhen(attempts -> attempts
.zipWith(Observable.range(1,3), (n, i) -> i) // retry maximum of 3 times
.flatMap(i -> {
System.out.println("Delaying retry by " + i + " second(s)");
return Observable.timer(i, TimeUnit.SECONDS); //delay the resubscribe
})
)
.toBlocking()
.forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment