작성
·
607
0
12:03분 쯤에 완성된 코드
List<CompletableFuture<String>> futures = Arrays.asList(hello, world);
CompletableFuture<String>[] futuresArray = futures.toArray(new CompletableFuture[futures.size()]);
CompletableFuture<List<String>> results = CompletableFuture.allOf(futuresArray)
.thenApply(v -> futures.stream()
.map(CompletableFuture::join) // join()은 Unchecked Exception, get()은 Checked Exception 발생
.collect(Collectors.toList()));
results.get().forEach(System.out::println);
Completablefuture 작업들을 컬렉션으로 만들지않고, thenApply()에서 결과값을 List로 만들어주기
CompletableFuture<List<String>> results = CompletableFuture.allOf(hello, world)
.thenApply(v -> Arrays.asList(hello.join(), world.join()));
results.get().forEach(System.out::println);
이 때 두 개의 코드는 동일한 기능으로 작동해도 된다고 봐도 될까요??
출력값도 동일하고, 강사님께서 말씀해주신대로 hello와 world 작업이 끝난 후에 그 결과값을 join()으로 가져와서 List로 만드는 기능으로 이해하고 있습니다.
헉... 빠른 답변 감사합니다.
좋은 강의 열심히 잘 듣도록 하겠습니다!