How to use retryWhen only 3 times then give up
How to use retryWhen only 3 times then give up I want to filter when specific exception occurs during execution of some of the upper chain function and try to retry the whole process only 3 times then if it still failes then give up. I came to something like this: val disposable = someFunction(someParameter, delay, subject) .flatMapCompletable { (parameter1, parameter2) -> anotherFunction(parameter1, parameter2, subject) } .retryWhen { throwable -> throwable.filter { it.cause?.cause is ExampleException1 || it.cause?.cause is ExampleException2 || it.cause is ExampleException3 } } .andThen(someStuff()) .subscribe({ Timber.d("Finished!") }, { Timber.d("Failed!") }) How to do it properly? 2 Answers 2 You may use zipWith with a range to achieve this. zipWith range .retryWhen { erro...