I am a beginner with rxjava/rxkotlin/rxandroid.
I need to deal with three diferent async-calls in a sequence.
The problem is that the first step returns a Single<LocationResult>
, the second a Completable
and the third again a Completable
.
(Single -> Completable -> Completable)
The problem is now that the last Completable
depends on the data of the first Single
My current solution:
I think this is a bad solution, but I don't know how to do this right.
val ft = FenceTransaction(applicationContext, apiClient)
stream
.flatMap { locationResult ->
ft.removeAll()
return@flatMap ft.commit().toSingle({ return@toSingle locationResult })
}
.flatMapCompletable {
ft.recycle()
ft.setZone(it.location.longitude, it.location.latitude, ZONE_RADIUS)
val dots = DotFilter().getFilteredDots()
for (dot in dots) {
ft.addDot(dot)
}
return@flatMapCompletable ft.commit()
}
.subscribeBy(
onComplete = {
"transaction complete".logi(this)
},
onError = {
"transaction error".logi(this)
})
Is this approch the correct way to do it?
And how should I dispose the Completeables
?
Generally when should I dispose Observables
?