[ https://issues.apache.org/jira/browse/KAFKA-6900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16474343#comment-16474343 ]
Richard Tjerngren commented on KAFKA-6900: ------------------------------------------ I would love to contribute this code change myself. However I don't seem to have permissions to assign it to myself, if someone can do that for me that would be great! > 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)