Created
July 14, 2015 07:31
-
-
Save djensen47/726b5883aa139f6f6323 to your computer and use it in GitHub Desktop.
RxJava retryWith example
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
// 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