Search code examples
androidkotlinretrofitrx-javarx-java-completable

RxJava Completable.andThen never triggers the second Completable


I'm trying to chain two reactive calls which return Completable using retrofit on android:

val userRequest = ...
val languageRequest = ...

return userService.updateUser(userRequest)
    .andThen { userService.updateMessagingUserLanguages(user.id, languageRequest) }
    .doOnComplete { userRepository.updateUser(user) }

which are defined as follow:

@PUT("$BASE_USER_URL")
fun updateUser(@Body user: UserRequest): Completable

@PUT("$BASE_URL/{userId}/languages")
fun updateMessagingUserLanguages(@Path("userId") userId: Long, @Body request: MessagingLanguageDTO): Completable

The first Completable succeed and returns a response with a 200 status. However, the second call is never triggered (it never appears in my log and does not pass my breakpoint).

What am I missing here?


Solution

  • Try:

    andThen(userService.updateMessagingUserLanguages(user.id, languageRequest))
    

    IOW, replace the lambda expression as a parameter with the actual Completable that you want to add to the chain.