Search code examples
rx-java2

How to prevent Rxjava Subject on "onComplete"?


I need a RxJava subject that ignore onComplete(), So even I used RxRelay, it call onComplete yet :(

private val mDisposables = CompositeDisposable()
private val mRelay: BehaviorRelay<Boolean> = BehaviorRelay.createDefault(true)
....
mDisposables += mRelay
        .observeOn(io)
        .throttleLatest(5, SECONDS)
        .flatMap { ... }
        .zipWith(...)
        .switchMap {...}
        .subscribeOn(io)
        .subscribeWith(object : DisposableObserver<UiData>() {
          override fun onComplete() {
            Timber.d("COMPLETED")
          }

          override fun onNext(it: UiData) {
            Timber.d(it.toString())
          }

          override fun onError(e: Throwable) {
            Timber.e(e)
          }
        })
  }

Why always do onComplete call?


Solution

  • It's probably your usage of .zipWith which limits the stream to the shortest participant, regardless of whether the other streams ever finish.