Skip to content

Instantly share code, notes, and snippets.

Created April 25, 2019 09:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
RxJava 2 extension function to do something and retry after error
package com.antonshilov.rxextensions
import io.reactivex.Single
fun <T, R> Single<T>.doOnErrorAndRetry(action: Single<R>): Single<T> =
onErrorResumeNext {
action.flatMap { this }
fun main() {
var x = 0
val consumeX = Single.fromCallable {
if (x == 0) throw RuntimeException()
else "OK"
val changeX = Single.fromCallable {
x = 1
val res = consumeX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment