trello-archive/RxLifecycle

bindUntilEvent work incorrect

Closed this issue · 1 comments

The code below worked in a extension function for Observable, I use that to do network request, and I want to unSubscribe the subscriber when the RxFragment(RxActivity) is no longer exists.

But when I upgrade RxJava and RxLifecycle from 2.x to the latest, I can no longer finish the auto unsubscribe with the bindUntilEvent api. Then I replaced this by compose api as below which has commented, but that is not working too. Finally I resolved this problem by bindToLifeCycle.
So, is there a bug in your lib, or is't just my stupid fault?

val observable = subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .bindToLifecycle(targetView)
//          .bindUntilEvent(targetView, FragmentEvent.DESTROY_VIEW)
//          .compose(targetView.bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .doOnSubscribe {
                onStart?.invoke()
            }

observable?.subscribeWithErrorHandling(object : AbsObserver<T>(targetView) {
    override fun onSubscribe(d: Disposable) {
    }

    override fun onComplete() {}

    override fun onNext(value: T) {
        success.invoke(value)
        onComplete?.invoke()
    }

    override fun onDataEmpty() {
        success.invoke(null)
        onComplete?.invoke()
    }

    override fun onError(httpCode: HttpCode,
                         businessCode: Int?,
                         error: String): Boolean {
        return fail?.invoke(httpCode, businessCode, error) ?: false
    }
})

And then I test the compose/bindUntilEvent/bindToLifecycle in a simple way as below, they all work well.
So it's not your lib problem, it's my fault.
But I am confused now.

override fun onStart() {
    super.onStart()
    val observable = Observable.timer(5_000, TimeUnit.MILLISECONDS)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .bindToLifecycle(this)
//         .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
//         .bindUntilEvent(this, FragmentEvent.DESTROY_VIEW)

    observable.subscribe {
        onError(HttpCode.NOT_FOUND, 100, "错误错误错误")//just show a dialog in the main thread
    }
}