Hi there. I'm trying to build chain of requests th...
# rx
u
Hi there. I'm trying to build chain of requests that consumes paginated response from server. I'm using
concatMap
operator:
Copy code
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.