Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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?
–
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
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.