Class CancellableFuture<T>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<T>
-
- org.jetbrains.bsp.bazel.server.bsp.CancellableFuture<T>
-
- All Implemented Interfaces:
java.util.concurrent.CompletionStage<T>,java.util.concurrent.Future<T>
public class CancellableFuture<T> extends java.util.concurrent.CompletableFuture<T>JDK's CompletableFuture does not handle cancellation well. When a `cancel` method is called on a derived future, created with a transformation method like `thenApply`, the cancellation is not propagated back to the original future. Try this code to see the difference: ``` public static void main(String[] args) throws InterruptedException { var f1 = CancellableFuture.from(new CompletableFuture<>()); var f2 = f1.thenApply(x ->x); f2.cancel(true); System.out.println(f1.isCancelled()); } ``` If you remove "CancellableFuture.from" call, you will get `false` instead of `true`
-
-
Constructor Summary
Constructors Constructor Description CancellableFuture(java.util.concurrent.CompletableFuture<?> original)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)static <U> CancellableFuture<U>from(java.util.concurrent.CompletableFuture<U> original)<U> java.util.concurrent.CompletableFuture<U>newIncompleteFuture()-
Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
-
-
-
Method Detail
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
newIncompleteFuture
public <U> java.util.concurrent.CompletableFuture<U> newIncompleteFuture()
- Overrides:
newIncompleteFuturein classjava.util.concurrent.CompletableFuture<T>
-
from
public static <U> CancellableFuture<U> from(java.util.concurrent.CompletableFuture<U> original)
-
-