File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1919public final class CompletableFutures {
2020 private CompletableFutures () {}
2121
22+ /**
23+ * A utility method to cancel the JSON-RPC request associated with the given future.
24+ * <p>
25+ * If the given future does not pertain to a JSON-RPC request or is <code>null</code>,
26+ * this method has no effect.
27+ *
28+ * @param future a {@link CompletableFuture}, or <code>null</code>
29+ * @param cancelRootFuture if <code>false</code>, this method will only ensure that a cancel
30+ * notification has been sent for the pending request to the remote endpoint, without attempting
31+ * to cancel any future pertaining to the request; if <code>true</code>, this method will
32+ * also attempt to cancel the root future for the request
33+ * @return <code>false</code> if the given future does not pertain to a JSON-RPC request
34+ * or is <code>null</code>; <code>true</code> otherwise
35+ */
36+ public static boolean cancelRequest (CompletableFuture <?> future , boolean cancelRootFuture ) {
37+ if (future instanceof JsonRpcRequestFuture ) {
38+ if (cancelRootFuture ) {
39+ ((JsonRpcRequestFuture <?>) future ).getRoot ().cancel (true );
40+ } else {
41+ ((JsonRpcRequestFuture <?>) future ).cancelRequest ();
42+ }
43+ return true ;
44+ }
45+ return false ;
46+ }
47+
2248 /**
2349 * A utility method to create a {@link CompletableFuture} with cancellation support.
2450 *
You can’t perform that action at this time.
0 commit comments