Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply compose async #97

Merged
merged 4 commits into from
Dec 12, 2023
Merged

Conversation

thiml
Copy link
Contributor

@thiml thiml commented Nov 27, 2023

Context

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.

Copy link
Contributor

@caesar-ralf caesar-ralf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will come in the next release

@caesar-ralf caesar-ralf merged commit 203ec10 into spotify:master Dec 12, 2023
3 checks passed
@thiml thiml deleted the supplyComposeAsync branch December 13, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants