Is there a way to combine the shot list? I have a list of ListenableFutures, each of which will catch an exception (if any) and store it in a Result instance. Finally, I want to throw an exception if any of the results of ListenableFutures contains a throw. The problem is how to combine multiple bookmarks, because there may be several futures that fail?
List<ListenableFuture<Result>> futureList = new ArrayList<>();
futureList.add(future1);
futureList.add(future2);
futureList.add(future3);
ListenableFuture<List<Result>> future = futureFutures.successfulAsList(futureList);
return Futures.transform(future, new Function<List<Result>, FinalResult>() {
@Override
public FinalResult apply(List<Result> resultList) {
List<Throwable> throwableList = new ArrayList<>();
for (Result result : resultList) {
if (result.getThrowable() != null) {
throwableList.add(result.getThowable());
}
}
if (!throwableList.isEmpty()) {
Throwable.propagateList(throwableList);
}
.....
return finalResult;
}
},
MoreExecutors.sameThreadExecutor());
source
share