Skip to content

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

Closed
@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!

Activity

akarnokd

akarnokd commented on May 9, 2016

@akarnokd
Member

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.

akarnokd

akarnokd commented on Jun 17, 2016

@akarnokd
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @akarnokd@superyfwy

        Issue actions

          How to delay to call “onError”? concatDelayError is not ok. · Issue #3908 · ReactiveX/RxJava