我有方法:
for(int i = 0; i< 10; i++){
Observable<ProductsResponse> products = restApiFactory.getProductService().getProducts(i)
}
如何使用不同的ID发出10个请求并返回ONE reault:
public class ProductsResponse {
private String status;
private String message;
private List<ProductItem> productItems;
}
如何获得合并结果?
{{1}}
我需要列出每个请求的数据
答案 0 :(得分:0)
应该可以做类似的事情:
List<Observable< ProductsResponse>> productsResponseObservableList = new ArrayList<>();
for(int i = 0; i< 10; i++){
productsResponseObservableList.add(restApiFactory.getProductService().getProducts(i));
}
Observable.combineLatest(productsResponseObservableList, args -> Arrays.asList(Arrays.copyOf(args, args.length, ProductsResponse[].class)))
.subscribe(responseList -> {
});