Skip to content

Java CompletableFuture

Fernando Benjamin edited this page Aug 24, 2020 · 1 revision
           List<CompletableFuture<Optional<Long>>> completableFutureList = loans.stream()
                    .map(loan -> CompletableFuture.supplyAsync(() -> processResponse(loan), executorService))
                    .collect(Collectors.toList());

            List<Optional<Long>> result = completableFutureList.stream()
                    .map(CompletableFuture::join)
                    .collect(Collectors.toList());

Clone this wiki locally