Rxjava2 可流动不触发 onComplete
Rxjava2 flowable not firing onComplete
这是代码
private fun setUpDistrictSpinner() {
commonRepo.getAllDistricts()
.observeOn(AndroidSchedulers.mainThread())
.flatMap { list -> Flowable.fromIterable(list) }
.map { district ->
districtNameList.add(district.district_name)
district
}.subscribe(object:Subscriber<District>{
override fun onComplete() {
labSelectionInterface.loadDistricts(districtNameList)
Timber.d("district List loaded total " + districtList.size)
}
override fun onError(t: Throwable?) {
t!!.printStackTrace()
}
override fun onNext(t: District) {
districtList.add(t)
}
override fun onSubscribe(s: Subscription) {
s.request(Long.MAX_VALUE)
}
})
}
onNext 正在触发,但 onComplete 不会触发。也没有错误消息。我正在将地区列表加载到微调器中。使用 Room 数据库和 Kotlin
这是我得到 Flowable
的地方
fun getAllDistricts(): Flowable<List<District>> {
Timber.d("District list accessed")
return appDatabase.districtDao().getAllDistricts()
.subscribeOn(Schedulers.io())
}
Room 返回的 Flowable
从未完成。它允许您在数据库修改时接收更新。
Here’s how the Flowable behaves:
- When there is no user in the database and the query returns no rows, the Flowable will not emit, neither onNext, nor onError.
- When there is a user in the database, the Flowable will trigger onNext.
- Every time the user data is updated, the Flowable object will emit automatically, allowing you to update the UI based on the latest data.
如果你想接收onComplete
事件,切换到Maybe
。你应该阅读这个 article.
这是代码
private fun setUpDistrictSpinner() {
commonRepo.getAllDistricts()
.observeOn(AndroidSchedulers.mainThread())
.flatMap { list -> Flowable.fromIterable(list) }
.map { district ->
districtNameList.add(district.district_name)
district
}.subscribe(object:Subscriber<District>{
override fun onComplete() {
labSelectionInterface.loadDistricts(districtNameList)
Timber.d("district List loaded total " + districtList.size)
}
override fun onError(t: Throwable?) {
t!!.printStackTrace()
}
override fun onNext(t: District) {
districtList.add(t)
}
override fun onSubscribe(s: Subscription) {
s.request(Long.MAX_VALUE)
}
})
}
onNext 正在触发,但 onComplete 不会触发。也没有错误消息。我正在将地区列表加载到微调器中。使用 Room 数据库和 Kotlin 这是我得到 Flowable
的地方 fun getAllDistricts(): Flowable<List<District>> {
Timber.d("District list accessed")
return appDatabase.districtDao().getAllDistricts()
.subscribeOn(Schedulers.io())
}
Room 返回的 Flowable
从未完成。它允许您在数据库修改时接收更新。
Here’s how the Flowable behaves:
- When there is no user in the database and the query returns no rows, the Flowable will not emit, neither onNext, nor onError.
- When there is a user in the database, the Flowable will trigger onNext.
- Every time the user data is updated, the Flowable object will emit automatically, allowing you to update the UI based on the latest data.
如果你想接收onComplete
事件,切换到Maybe
。你应该阅读这个 article.