-
-
Save pyadav/1d48db59bcaa38068d2e87bdd2bafa10 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