Class CancellableFuture<T>
java.lang.Object
java.util.concurrent.CompletableFuture<T>
org.jetbrains.bsp.bazel.server.bsp.CancellableFuture<T>
- All Implemented Interfaces:
CompletionStage<T>,Future<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`
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) static <U> CancellableFuture<U>from(CompletableFuture<U> original) <U> CompletableFuture<U>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, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, 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
-
Constructor Details
-
CancellableFuture
-
-
Method Details
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
newIncompleteFuture
- Overrides:
newIncompleteFuturein classCompletableFuture<T>
-
from
-