java - completable future in list stop if exception
问题描述
I have a code where I am using completable future in a loop,
list.map(l -> CompletableFuture
.supplyAsync(() -> [API_CALL])
.exceptionally(e -> {
throw new RuntimeException("Failed to hit the url");
}).thenComposeAsync(obj -> anotherApiCall(obj), taskExecutor)));
I am making two API calls one after other in a loop. I want to stop the loop, i.e. map() in case of exception thrown. Is it possible with CompletableFuture?
解决方案
推荐阅读
- sql - 无法针对大小为 1024 且该字段包含 1008 个字符的列保存值
- sql-server - 如何从另一个查询的结果集中创建表
- spring-data - Spring数据deleteBy查询不返回已删除的对象
- python - Numpy方法返回数组中数组出现的索引
- ios - 由于 libstdc++,无法为 ios 构建 openh264
- uitableview - UITableViewDiffableDataSource:如何设置节标题?
- reactjs - 不变违规:无效的钩子调用
- react-native - “Redux 无法正常登录”
- routing - 使用 symfony 4 创建后台和前台应用程序的最佳方式
- node.js - 使用 NodeJS 发出 http 请求并访问返回的 cookie