How do i update a source observable on retry?
List<String> ids = new ArrayList<>(); // A,B,C
Observable.from(ids)
.retryWhen(errors -> {
return errors
.zipWith(Observable.range(0, 1), (n, i) -> i)
.flatMap(retryCount -> Observable.timer((long) Math.pow(2, retryCount), TimeUnit.MINUTES));
})
.subscribe(....);
now rather than passing //A,B,C as ids if i want to pass some other values. How do i do it? or is this even the right approach?
Use defer
. This would allow ids
to be re-computed:
Observable.defer(() -> {
List<String> ids = // compute this somehow
return Observable.from(ids);
}).retryWhen(...
Documentation on the defer operator
onErrorResumeNext
could be used. You probably need some additional logic to match your use case. Documentation for error handling operators here.
List<String> ids = new ArrayList<>(); // A,B,C
List<String> ids2 = new ArrayList<>(); // D,E,F
Observable.from(ids)
.onErrorResumeNext(throwable -> {
return Observable.from(ids2);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With