When should Java futures be propagated vs joining them immediately?

Viewed 53

In a language like Javascript once a function is async its caller also has to be marked as async so it's very straightforward. In Java however if an API method x() returns a CompletableFuture we have the choice of either joining it immediately thus blocking or have the caller y() return CompletableFuture as well.

If x() method is called multiple times in a loop then it's a clear advantage not to join it immediately so that multiple x() calls are performed concurrently.

However, if I have just one call to x() and then I need to do something with its result then it seems that there's no advantage not to join it immediately. Am I missing something? Are there any advantages to keep propagating CompletableFutures along the call stack in this case?

0 Answers
Related