我想合并两个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
}
}
如何解决?
答案 0 :(得分:1)
(来自评论:)
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
}
}