Reputation: 4639
I want to merge two Completable
-s but there is no final onComplete
call.
This is my code:
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
}
}
How to fix it?
Upvotes: 0
Views: 1746
Reputation: 70007
(from the comments:)
toFuture
requires the source to complete. Use something like this:
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
}
}
Upvotes: 1