Skip to content

Commit

Permalink
Refact: use CompletableFutureUtils.allOf
Browse files Browse the repository at this point in the history
  • Loading branch information
bsc7 committed Nov 5, 2024
1 parent fcea4e6 commit 912a334
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.common.network.Address;
import bisq.common.util.CollectionUtil;
import bisq.common.util.CompletableFutureUtils;
import bisq.network.NetworkService;
import bisq.rest_api.JaxRsApplication;
import bisq.rest_api.RestApiApplicationService;
Expand Down Expand Up @@ -82,7 +83,9 @@ public List<String> getAddressList() {
)
@GET
@Path("get-report/{address}")
public ReportDto getReport(@Parameter(description = "address from which we request the report") @PathParam("address") String address) {
public ReportDto getReport(
@Parameter(description = "address from which we request the report")
@PathParam("address") String address) {
try {
return fetchReportForAddress(address).join();
} catch (Exception e) {
Expand Down Expand Up @@ -111,17 +114,13 @@ public List<ReportDto> getReports(
throw new RuntimeException("Failed to parse addresses from CSV input: " + addresses);
}


List<CompletableFuture<ReportDto>> futures = addressList.stream()
.map(this::fetchReportForAddress)
.toList();

CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
CompletableFuture<List<ReportDto>> allFutures = CompletableFutureUtils.allOf(futures);

return allFutures.thenApply(v -> futures.stream()
.map(CompletableFuture::join)
.toList())
.join();
return allFutures.join();
}

private CompletableFuture<ReportDto> fetchReportForAddress(String addressString) {
Expand Down

0 comments on commit 912a334

Please sign in to comment.