问题
I have this code which I can use with concat but what I need is a way of passing Iterator so that I can add or remove items which isn't possible with this code.
I want to be able to remove and add items to concat without causing java.util.ConcurrentModificationException I need to do this for different purpose such as if some items are success remove them and retry others. Or if token is invalid then remove all and refresh token and add all with modified token.
Observable userObservable = getUserObservable(token);
Observable userObservable = getMerchantObservable(token);
List<Observable<?>> observables = Arrays.asList(userObservable, merchantObservable);
Observable.concat(observables)
.doOnNext(
result -> observables.remove(0)
//then if token refreshed call is success then
//observables.clear()
//observables.add(updatedUserObservable)
//observables.add(updateMerchantObservable)
)
//.doOnError(error -> System.out.println(error.getMessage()))
.doOnError(error -> {
System.out.println(error.getMessage());
if(((HttpException) error).code() == 401){
observables.clear();
observables.add(getRefreshTokenObservable());
}
})
.retryWhen(new RetryWithDelay(5, 2000))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
result -> System.out.println(result),
error -> System.out.println("onError called!"));
来源:https://stackoverflow.com/questions/61352701/passing-list-to-rxjava-concat-and-when-remove-item-in-onnext-or-onerror-causes-c