How do I chain a Single to a Completable such that it get subscribed to when the Completable is complete?
repository.downloadUser()
is the Single.
Based on debugging it seems that the Single in this method gets called but never subscribed (i.e. the downloadUser()
method gets called but no code inside the Single that it creates is called).
The question is, how do I get the repository.downloadUser()
Single to be subscribed to in the chain using the original subscriber? What am I missing or doing wrong? Or is this not possible?
fun login(username: String, password: String): Completable {
return repository.login(username, password)
.andThen {
repository.downloadUser() // This is a Single
.flatMap { downloadedUser ->
user = downloadedUser
it.toSingle()
}
// When I get this part working there are other things I want to
// chain as well.
}
Edit: I'll probably just break it up into two calls, one for the Completable, and then another one for the rest. However it would still be good to know if this is possible or not if anyone knows...
Pretty sure this is your use of curly braces. Kotlin thinks you're invoking the RxJava method
public final Completable andThen(CompletableSource next) {
return concatWith(next);
}
meaning the return type is Completable
, but you want it as a Single
. What you'll need is
repository.login(username, password)
.andThen(repository.downloadUser())
.flatmap { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With