-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
…sage of CompletableFuture APIs. Updated code to use the new APIs. Signed-off-by: Simone Bordet <[email protected]>
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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.
…sage of CompletableFuture APIs.
Updated code to use the new APIs.
Signed-off-by: Simone Bordet [email protected]