ubu
10/03/2018, 12:08 PMconcatMap
operator:
fun searchPlacesOnRouteTest(encodedRoute: String, startId: Int, categories: List<Int>): Observable<PagedResponse<PlaceModel>> {
return searchPlacesOnRoutePaginated(encodedRoute, startId, categories)
//.concatMap { response -> Observable.just(response) }
.doOnNext { println("response: data size : ${it.data.size}, has next page : ${it.hasNextPage}") }
}
private fun searchPlacesOnRoutePaginated(encodedRoute: String, startId: Int, categories: List<Int>): Observable<PagedResponse<PlaceModel>> {
return api.searchPlacesOnRoute(encodedRoute, categories, startId).concatMap { response ->
if (response.hasNextPage)
Observable.just(response).concatWith {
val newStartId = response.data.last().id
searchPlacesOnRoutePaginated(encodedRoute, newStartId, categories)
}
else
Observable.just(response)
}
}
The problem (with the implementation above) is that observable emits only the first item. I suppose that first Observable
source does not complete. How could one fix that?
Thanks.