My requirement is read data from local database first, and then read data from network. The following is the code:
Observable<String> obsLocal =
Observable.<String>create(subscriber -> {
//do work
for(int i=0;i<Integer.MAX_VALUE / 10; i++){
}
subscriber.onNext("local");
subscriber.onCompleted();
});
Observable<String> obsNet =
Observable.<String>create(subscriber -> {
subscriber.onNext("net");
subscriber.onCompleted();
});
Observable.<String>concat(obsLocal, obsNet)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(v->{
LogUtil.d("onNext " + v);
}, throwable -> {
LogUtil.d("onerror ");
}, ()->{
LogUtil.d("oncomplete ");
});
Now, if no error, everything is ok.
But if an error occurs, the execution will break immediately.
If I use the following code:
Observable<String> obsNet =
Observable.<String>create(subscriber -> {
subscriber.onError(new RuntimeException());
});
obsLocal would stop immediately too.
I expect onError is called after obsLocal executing completely. How can I do?
By the way, concatDelayError is not ok.
If you have any suggestion or solution, please let me know. Thanks a lot!
What's happening is that the error cuts ahead of the value in observeOn. You have to use observeOn(scheduler, true) to delay the error itself and keep the total event order.
I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.
Most helpful comment
What's happening is that the error cuts ahead of the value in
observeOn. You have to useobserveOn(scheduler, true)to delay the error itself and keep the total event order.