[ https://issues.apache.org/jira/browse/KAFKA-6900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16491604#comment-16491604 ]
Richard Tjerngren commented on KAFKA-6900: ------------------------------------------ Changes available at https://github.com/apache/kafka/pull/5080 > 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)