Skip to content

How to delay to call “onError”? concatDelayError is not ok. #3908

@superyfwy

Description

@superyfwy

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions