I've faced to some strange behavior of flatMapCompletable
function. In the code snippet below I have multiple inner flatMapCompletable. Line marked with * doesn't call code in andThan
. Although any other compellable in this code successfully executes andThan
.
I suggested that my inner Completable.complete()
doesn't call desired subscriber's Complete so I tried to play around braces, but nothing helps.
Also according to the documentation, all flatMap operations are flatten to one chain, so I can't understand why it doesn't work here.
Maybe anyone also got this problem and found a solution?
Thank everyone for advice!
fileManager
.checkIsUserResourceExists(user.name)
.flatMapCompletable { exists ->
if (exists) {
Completable.complete()
} else {
return@flatMapCompletable
checkShouldAskForCellularDataUsage()
.flatMapCompletable { shouldAskForMobileDataUsage ->
if (shouldAskForMobileDataUsage) {
return@flatMapCompletable cellularNetworkUsageApprovedRelay
.switchMapCompletable{
if (it) {
Log.d("USER_DATA_OPERATION", "DOWNLOAD APPROVED")
* return@switchMapCompletable Completable.complete()
} else
return@switchMapCompletable retryMobileDownloadRelay
.switchMapCompletable {
downloadUserProfileResource(effect)
}
}
} else {
Completable.complete()
}
}
.andThen(fileManager.checkEnoughSpace(userProfile.size * 3))
.andThen(apiManager.getUserResource(userProfile.resource!!).toObservable())