[ https://issues.apache.org/jira/browse/KAFKA-6900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16490546#comment-16490546 ]
ASF GitHub Bot commented on KAFKA-6900: --------------------------------------- RichoDemus opened a new pull request #5080: KAFKA-6900: Add thenCompose to KafkaFuture URL: https://github.com/apache/kafka/pull/5080 Add KafkaFuture.thenCompose which behaves similarly to KafkaFuture.thenAccept except that it flattens Futures. This means that it's possible to do another async call inside thenCompose without getting a KafkaFuture<KafkaFuture<T>> It's implemented to have the same signature and behaviour as CompletableFuture.thenCompose Tested both by writing unit tests but I've also done manual testing ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add thenCompose to KafkaFuture > ------------------------------ > > Key: KAFKA-6900 > URL: https://issues.apache.org/jira/browse/KAFKA-6900 > Project: Kafka > Issue Type: Improvement > Components: clients > Affects Versions: 1.1.0 > Reporter: Richard Tjerngren > Priority: Minor > > KafkaFuture supports Future chaining via the thenApply method just like > CompletableFuture, however, thenApply is not intended to be used for lambdas > that in turn return a future: > > {code:java} > KafkaFutureImpl<String> future = new KafkaFutureImpl<>(); > KafkaFuture<KafkaFuture<String>> nestedFuture = future.thenApply(result -> > methodThatReturnsFuture(result)); > {code} > Completable future has a method called thenCompose > [javadoc|https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/CompletionStage.html#thenCompose(java.util.function.Function)] > The would be: > {code:java} > public KafkaFuture<R> thenCompose(Function<T, KafkaFuture<T> func);{code} > So the above example would look like this: > {code:java} > KafkaFutureImpl<String> future = new KafkaFutureImpl<>(); > KafkaFuture<String> nestedFuture = future.thenCompose(result -> > methodThatReturnsFuture(result)); > {code} > This would enable developers to chain asynchronous calls in a more natural > way and it also makes KafkaFuture behave more similar to Javas > CompletableFuture and Javascripts Promise > -- This message was sent by Atlassian JIRA (v7.6.3#76005)