RxJava Completable onErrorComplete+merge 不起作用



我想合并两个Completable-s,但没有最终的onComplete调用。

这是我的代码:

private fun dataLoading(): Completable {
return Completable.merge(listOf(
method1(),
method2()))
.doOnComplete {
// not called
}
}
private fun method1(): Completable {
return merge(loadHistory(),
loadData(),
loadFavorites(),
loadBalance())
.doOnComplete {
// called
}
}
private fun method2(): Completable {
return Single
.fromFuture(locationSubject.toFuture()) // BehaviorSubject
.timeout(1, TimeUnit.SECONDS) // waiting for coordinates 1 sec
.flatMapCompletable { onLocationLoaded(it) } // not called
.onErrorComplete() // got TimeoutException here
.doOnComplete {
// called
}
}

如何解决?

(来自评论:(

toFuture需要源才能完成。使用类似这样的东西:

private fun method2(): Completable {
return locationSubject  // BehaviorSubject
.firstOrError() // <---------------------------------------------- Single
.timeout(1, TimeUnit.SECONDS) // waiting for coordinates 1 sec
.flatMapCompletable { onLocationLoaded(it) } // not called
.onErrorComplete() // got TimeoutException here
.doOnComplete {
// called
}
}

相关内容

  • 没有找到相关文章

最新更新