RxJava / RxAndroid中的PublishSubject导致崩溃onError并跳过onNext

时间:2018-06-24 07:21:03

标签: java android rx-java rx-android publishsubject

我有这样的代码:

流程X:

 getLocationObservable() // ---> async operation that fetches the location. 
    //  Once location is found(or failed to find) it sends it to this filter :
            .filter(location -> {
                --- Operation A ---
                after finishing the operation A, I either return 'true' and continue 
                 to the next observable which is a Retrofit server call, or simply 
                  return 'false' and quit.
            })
            .flatMap(location -> getRetrofitServerCallObservable( location )
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread()))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    new Observer<MyCustomResponse>() {
                        @Override
                        public void onSubscribe(Disposable d) {
                            _disposable = d;
                        }
                        @Override
                        public void onNext(MyCustomResponse response) {

                        }
                        @Override
                        public void onError(Throwable e) {

                        }
                        @Override
                        public void onComplete() {

                        }
                    });

在Location类中是这样的:

 private PublishSubject<Location> locationPublishSubject = PublishSubject.create();

    public Observable<Location> getLocationObservable() {
        return locationPublishSubject;
    }

    and then...
    locationPublishSubject.onNext( foundLocation );

PublishSubject问题:

  1. 如果我打电话给locationPublishSubject.onError( new <some mock exception> )-> io.reactivex.exceptions.UndeliverableException
  2. 崩溃
  3. 如果我在locationPublishSubject.onComplete之后致电onNext-> onNext不  发生。它直接跳到onComplete

0 个答案:

没有答案