I am using Completable futures in java 8 and I want to write a method that, based on a received parameter, either runs multiple tasks with side effects in parallel and then return their "combined" future (using CompletableFuture.allOf()
), or does nothing and returns an already-completed future.
However, allOf
returns a CompletableFuture<Void>
:
public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs)
And the only way to create an already-completed future that know is using completedFuture()
, which expects a value:
public static <U> CompletableFuture<U> completedFuture(U value)
Returns a new CompletableFuture that is already completed with the given value.
and Void
is uninstantiable, so I need another way to create an already-completed future of type CompletableFuture<Void>
.
What is the best way to do this?