I'm trying to create a server call using RxJava2 library that will try to poll server for answer and if receives exception 3 times in a row to return that exception
I've set up a basic call that fetches the response from the server
final Observable<ResponseValue> responseValueObservable = Observable
.fromCallable((Callable) (c) -> return getDispatcher().performSubmit(submitValue);
}
});
return responseValueObservable
.retry(3)
.subscribeOn(Schedulers.io()
.onError((t) -> { log.error(t); Observable.timer(2, SECONDS);}
.retryUntil(() -> { return retryIsEnabled }
so getDispatcher().performSubmit(submitValue)
returns either SubmitException
or ResponseValue
object.
I need the code to retry 3 times, pausing after each exception for 2 seconds and return either ResponseValue
or the last SubmitException