0
List<Object> someList = getSomeList();

someList.stream().forEach( (callSomeCompletableFutureFunction)
                .thenCompose ( call another completableFutureFunction)
                .whenComplete(response, exception) -> {
                        if (Objects.nonNull(response)) {
                              // do something
                                 someCode
                        } else {
                              // log or throw error
                             someCode
                   }
         } ); // everything is in forEach loop

What is if I directly call forEach on list ? How will it impact on completableFuture which is getting processed inside the callSomeFuntion ? What is the difference between stream and foreach in this case [suppose you are sending SMS in Async manner after collecting data in sequence of thenCompose call] ?

Hiren
  • 242
  • 1
  • 9
  • There's no difference. – shmosel Jun 20 '19 at 19:37
  • You are saying that list.stream() and list.stream.forEach() will make no difference here with CompletableFuture getting executed inside forEeach() with thenCompse ? – Hiren Jun 20 '19 at 19:40
  • That's correct. – shmosel Jun 20 '19 at 19:44
  • I don't think this is a duplicate question. It is not simple case, I have mentioned that CompeletableFuture is involved inside the ForEach and I do not know if that will make any difference with the combination of stream and stream + forEach Samuel Philipp, Mark Rotteveel – Hiren Jul 01 '19 at 07:27
  • For the third time, there's no difference. – shmosel Jul 01 '19 at 07:28

0 Answers0