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

Introduced [Callback|Promise]Completable.with(Consumer) to simplify u… #8620

Merged
merged 1 commit into from
Sep 27, 2022

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Sep 26, 2022

…sage of CompletableFuture APIs.

Updated code to use the new APIs.

Signed-off-by: Simone Bordet [email protected]

…sage of CompletableFuture APIs.

Updated code to use the new APIs.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested review from joakime and lorban September 26, 2022 20:16
Copy link
Contributor

@lorban lorban left a comment

Choose a reason for hiding this comment

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

Callback.Completable.with() is a really nice improvement as it allows using the CompletableFuture API fluently.

The only small annoyance is that using with() in a fluent call chain lowers readability a bit, I wish we always provided a method that returns CompletableFuture as it would make the fluent call chains crystal clear.

Promise.Completable<String> promise = new Promise.Completable<>();
Content.Source.asString(charSetParts.get(0).getContent(), StandardCharsets.US_ASCII, promise);
defaultCharset = promise.get();
defaultCharset = Promise.Completable.<String>with(p -> Content.Source.asString(charSetParts.get(0).getContent(), StandardCharsets.US_ASCII, p))
Copy link
Contributor

Choose a reason for hiding this comment

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

Too bad we can't have Content.Source.asString(Source, Charset) that returns a CompletableFuture.

Content.Source.asString(request, StandardCharsets.UTF_8, p);
return p;
})
.thenCompose(ignored -> Promise.Completable.<String>with(p -> Content.Source.asString(request, StandardCharsets.UTF_8, p)))
Copy link
Contributor

Choose a reason for hiding this comment

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

It really show here that a Content.Source.asString that returns a CompletableFuture would be more elegant.

Content.Sink.write(response, true, content, c);
return c;
});
.thenCompose(content -> Callback.Completable.with(c -> Content.Sink.write(response, true, content, c)));
Copy link
Contributor

Choose a reason for hiding this comment

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

A Content.Sink.write that returns a CompletableFuture would be more elegant here too.

@sbordet sbordet merged commit 760257a into jetty-12.0.x Sep 27, 2022
@sbordet sbordet deleted the jetty-12.0.x-completable-with branch September 27, 2022 12:18
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