Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Introduce FutureUtils to reduce duplicated code around CompletableFuture #868

Merged
merged 6 commits into from
Feb 15, 2019

Conversation

ajsutton
Copy link
Contributor

PR description

Introduce FutureUtils to provide some commonly required functionality around CompletableFuture such as creating a future that is completed exceptionally, handling exceptionally completed futures by composing with another future and propagating the result or exception from one future to another.

Applies these utilities in a few places to simplify existing code. There will certainly be more places they could be used, but this is a start.

future.whenComplete(
(value, error) -> {
final CompletionStage<T> nextStep =
error != null ? errorHandler.apply(error) : completedFuture(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a try / catch around the errorHandler execution in case that function throws?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep seems like a good idea.

@ajsutton ajsutton merged commit d27656b into PegaSysEng:master Feb 15, 2019
@ajsutton ajsutton deleted the future-utils branch February 15, 2019 20:43
rain-on pushed a commit to rain-on/pantheon that referenced this pull request Feb 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants