Adds a utility function supplyAsyncCompose which removes the need for dereferencing the output of supplyAsync whenever the Supplier return type is a CompletionStage<T> to avoid bloating of unwrapping the nested CompletionStage<CompletionStage<T>>.
This is beneficial when one would like to create Future chains on top of the Supplied type:
Example
// Before
// databaseOperation returns a CompletionStage
CompletableFuture.supplyAsync(() -> databaseOperation().thenApply(DataBaseRow::toProto)).thenCompose(result -> result);
// After
// databaseOperation returns a CompletionStage
CompletableFuture.supplyAsyncCompose(() -> databaseOperation().thenApply(DataBaseRow::toProto));
NOTES
This might be achievable by wrapping every supplyAsync with the already existing dereference to get the same behaviour. This might be preferable, but if this seems valuable feel free to review and merge.
Context
Adds a utility function
supplyAsyncCompose
which removes the need for dereferencing the output ofsupplyAsync
whenever theSupplier
return type is aCompletionStage<T>
to avoid bloating of unwrapping the nestedCompletionStage<CompletionStage<T>>
.This is beneficial when one would like to create Future chains on top of the Supplied type:
Example
NOTES This might be achievable by wrapping every
supplyAsync
with the already existingdereference
to get the same behaviour. This might be preferable, but if this seems valuable feel free to review and merge.