Skip to content

Instantly share code, notes, and snippets.

@ahmedrizwan
Created January 17, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedrizwan/eeccafc31b9af42a349aaa8c96f59246 to your computer and use it in GitHub Desktop.
Save ahmedrizwan/eeccafc31b9af42a349aaa8c96f59246 to your computer and use it in GitHub Desktop.
Observable.fromPublisher<String> {
it.onNext("Doing a network call!")
Thread.sleep(1000) // Long running process
it.onError(Exception()) // Some error thrown
}.retryWhen { errors ->
errors.zipWith(Observable.range(1, 3) // Zip error observable with a range one
.concatMap { retryCount ->
Observable.timer(retryCount.toLong() * 10, TimeUnit.SECONDS)
}
)
}.blockingSubscribeBy(
onNext = { println(it) },
onError = { println(it) },
onComplete = { println("Complete") }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment