I have an use case where I have to return a CompletableFuture<Void>
from a function that composes 2 Completable Futures based on a condition.
Below is what I have right now -
private CompletableFuture<Void> processSomething(final SomeEvent event) {
final CompletableFuture<PaginatedQueryList<Detail>> detail = dao.getData(event.getOrderId());
return detail.thenApply(n -> n.stream()
.filter(i -> i.getBusinessType().equals(BusinessType.AWESOME))
.findFirst()
.filter(i -> i.getLastUpdateEventTimestamp() <= event.getCreationTime())) // This returns Optional<Detail>
.thenCompose(i -> i
.map(o -> deleteItem(event,o))
.orElse(CompletableFuture.completedFuture(null))); // deleteItem is a async call that returns CompletableFuture<Void>
}
Can the community check and and suggest any other approach ?
I particularly do not like returning explicitly CompletableFuture.completedFuture(null)
.