Class CompletableFutureUtils

java.lang.Object
dev.langchain4j.internal.CompletableFutureUtils

public class CompletableFutureUtils extends Object
Utility methods for working with CompletableFuture.
  • Method Details

    • propagateCancellation

      public static void propagateCancellation(CompletableFuture<?> from, CompletableFuture<?> to)
      Forwards cancellation from one future to another.

      CompletableFuture.cancel(boolean) does not propagate to the stages a future was derived from, so when from represents the future handed to a caller and to represents the underlying work (e.g. an in-flight HTTP request), cancelling from would otherwise leave to running. This method bridges that gap: once from completes, if it was cancelled, to is cancelled too.

      Parameters:
      from - the future whose cancellation should be propagated; ignored if null.
      to - the future to cancel when from is cancelled.