1

I've faced to some strange behavior of flatMapCompletablefunction. 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())
Ening
  • 455
  • 3
  • 19
  • Your code snippet is incomplete. Function defenitions are missing; balance of square brackets are fine, but their placement are incorrect. Fix your code in order to receive some interest in your question – Taras Mazepa Sep 22 '18 at 22:07

0 Answers0