问题
I am trying to hit an API call using retrofit and receive the response from the call. I am using the Single of Rxjava to get the response. What I need to do is that a retry if the call fails. I have gone through lots of examples but it seems none could have been a help (Also because of my limited knowledge on RXjava and Kotlin).
Below is the function which does the call and the retryWhen
function I wrote
override fun fetchMessage(southDataModel: SouthDataModel): Single<ArrayList<SouthDataResponseModel>> {
return retrofitService.getCTLNetworkService()
.fetchMessage(fetchMessageMapper.transform(southDataModel))
.map {
southDataResponseMapper.transform(it)
}
.retryWhen { error ->
error.flatMap {
Flowable.timer(1, TimeUnit.SECONDS)
}
}
}
This is exactly what I want to achieve
Single.timer(1, TimeUnit.SECONDS)
* .doOnSubscribe(s -> System.out.println("subscribing"))
* .map(v -> { throw new RuntimeException(); })
* .retryWhen(errors -> {
* AtomicInteger counter = new AtomicInteger();
* return errors
* .takeWhile(e -> counter.getAndIncrement() != 3)
* .flatMap(e -> {
* System.out.println("delay retry by " + counter.get() + " second(s)");
* return Flowable.timer(counter.get(), TimeUnit.SECONDS);
* });
* })
* .blockingGet();
Below is the error when I compile the code
Type mismatch: inferred type is (Throwable!) -> Flowable<Long!>! but ((Throwable!) -> Publisher!)! was expected
来源:https://stackoverflow.com/questions/59856216/retrywhen-is-giving-some-issues-when-using-with-single