I have an API that takes an Observable
that triggers an event.
I want to return an Observable
that emits a value every defaultDelay
seconds if an Internet connection is detected, and delays numberOfFailedAttempts^2
times if there's no connection.
I've tried a bunch of various styles, the biggest problem I'm having is retryWhen's
observable is only evaluated once:
Observable
.interval(defaultDelay,TimeUnit.MILLISECONDS)
.observeOn(Schedulers.io())
.repeatWhen((observable) ->
observable.concatMap(repeatObservable -> {
if(internetConnectionDetector.isInternetConnected()){
consecutiveRetries = 0;
return observable;
} else {
consecutiveRetries++;
int backoffDelay = (int)Math.pow(consecutiveRetries,2);
return observable.delay(backoffDelay, TimeUnit.SECONDS);
}
}).onBackpressureDrop())
.onBackpressureDrop();
Is there any way to do what I'm attempting to do? I found a related question (can't find it searching right now), but the approach taken didn't seem to work with a dynamic value.