The operation api.getProducts(..) with the help of Retrofit, we invoke a GET from another API. Now, repeatUntil() is used since the other API returns a page and there is a specific documentId that has more than 200 records, and for each invocation, for example, it only returns a page with 30 records, so 170 would be missing. records. So with repeatUntil I manage to get the 200 records and display them in a single invocation.
BUT, this happens to take about 7 seconds and I need to know if there is another way to do this without it being time consuming.
I use Spring Boot + RxJava
public TriFunction<Map<String, String>, String, ProductPending, Single<List<ProductSearch>>> getProducts() {
return (headers, documentId, product) -> api.getProducts(headers, documentId, EXTRA_FIELDS)
.map(response -> handleHeaderFromResponse().apply(product, response, headers))
.repeatUntil(() -> !product.isItemsPending())
.doOnNext( // evaluate miliseconds )
.anotherOperator(..)
.toList()
.doOnSuccess(productsSearch ->
log.debug(LOG_PREFIX + "Success PRODUCT-> getProduct -> documentId: {}",
personId.replaceAll("[\r\n]", StringUtils.EMPTY))
)
.doOnError(ex -> log.error(LOG_PREFIX + "Error Product -> getProducts-> DocumentId: {}", documentId.replaceAll("[\r\n]", StringUtils.EMPTY)))
.onErrorResumeNext(..)
.subscribeOn(io());
}