boolean isRetryButtonClicked = false;
.retryWhen(throwableFlowable -> throwableFlowable.skipWhile(throwable -> !isRetryButtonClicked)
.doOnNext(throwable -> Log.w("...", "doOnNext"))
.doOnComplete(() -> Log.w("...", "doOnComplete"))
.doOnError(throwable -> Log.w("...", "doOnError " + throwable))
.doOnSubscribe(subscription -> Log.w("...", "doOnSubscribe")))
If the isRetryButtonClicked
variable was false then it will not print doOnNext and that is okay because I told it to skip while isRetryButtonClicked
equal false, But when the user clicks on the retry button I'll change the isRetryButtonClicked
value to true, And after that it must start to print doOnNext but the current result is still not print anything.
retryWhen
needs a signal to perform the retry from that inner source. However, isRetryButtonClicked
is a field so changes to it are not signals. What you need is a Subject
. For example:
PublishSubject<String> subjectToRetry = PublishSubject.create();
source.retryWhen(errors -> errors.zipWith(subjectToRetry, (e, s) -> s))
.doOnNext(throwable -> Log.w("...", "doOnNext"))
.doOnComplete(() -> Log.w("...", "doOnComplete"))
.doOnError(throwable -> Log.w("...", "doOnError " + throwable))
.doOnSubscribe(subscription -> Log.w("...", "doOnSubscribe")))
// inside the retryButton's click handler:
subjectToRetry.onNext("Doit!");