Rxjava: How to delay to call ā€œonErrorā€? concatDelayError is not ok.

Created on 5 May 2016  Ā·  2Comments  Ā·  Source: ReactiveX/RxJava

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!

Question

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

perlow picture perlow  Ā·  3Comments

Jaap-van-Hengstum picture Jaap-van-Hengstum  Ā·  3Comments

yubaokang picture yubaokang  Ā·  3Comments

archenroot picture archenroot  Ā·  3Comments

ljf1172361058 picture ljf1172361058  Ā·  3Comments