Details
-
Improvement
-
Status: Patch Available
-
Minor
-
Resolution: Unresolved
-
1.1.0
-
None
-
None
Description
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:
KafkaFutureImpl<String> future = new KafkaFutureImpl<>(); KafkaFuture<KafkaFuture<String>> nestedFuture = future.thenApply(result -> methodThatReturnsFuture(result));
Completable future has a method called thenCompose javadoc
The would be:
public KafkaFuture<R> thenCompose(Function<T, KafkaFuture<T> func);
So the above example would look like this:
KafkaFutureImpl<String> future = new KafkaFutureImpl<>(); KafkaFuture<String> nestedFuture = future.thenCompose(result -> methodThatReturnsFuture(result));
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
Attachments
Issue Links
- links to