Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-6900

Add thenCompose to KafkaFuture

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Patch Available
    • Minor
    • Resolution: Unresolved
    • 1.1.0
    • None
    • clients
    • 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

          Activity

            People

              Unassigned Unassigned
              RichoDemus Richard Tjerngren
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: