Skip to content

Instantly share code, notes, and snippets.

@djensen47
Created October 5, 2015 20:25
Show Gist options
  • Save djensen47/a0612c2cd090c8d4372a to your computer and use it in GitHub Desktop.
Save djensen47/a0612c2cd090c8d4372a to your computer and use it in GitHub Desktop.
// from: http://www.slideshare.net/Couchbase/reactive-programmingrxjavaefficientdata-benchristensenmichaelnitschinger/75
Observable
.defer(() -> bucket.get("id"))
.retryWhen(attempts -> attempts
.zipWith(Observable.range(1,3), (n, i) -> i)
.flatMap(i -> {
System.out.println("Delaying retry by " + i + " second(s)");
return Observable.timer(i, TimeUnit.SECONDS)
})
)
.toBlocking()
.forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment