Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@
public final class CompletableFutures {
private CompletableFutures() {}

/**
* A utility method to cancel the JSON-RPC request associated with the given future.
* <p>
* If the given future does not pertain to a JSON-RPC request or is <code>null</code>,
* this method has no effect.
*
* @param future a {@link CompletableFuture}, or <code>null</code>
* @param cancelRootFuture if <code>false</code>, this method will only ensure that a cancel
* notification has been sent for the pending request to the remote endpoint, without attempting
* to cancel any future pertaining to the request; if <code>true</code>, this method will
* also attempt to cancel the root future for the request
* @return <code>false</code> if the given future does not pertain to a JSON-RPC request
* or is <code>null</code>; <code>true</code> otherwise
*/
public static boolean cancelRequest(CompletableFuture<?> future, boolean cancelRootFuture) {
if (future instanceof JsonRpcRequestFuture) {
if (cancelRootFuture) {
((JsonRpcRequestFuture<?>) future).getRoot().cancel(true);
} else {
((JsonRpcRequestFuture<?>) future).cancelRequest();
}
return true;
}
return false;
}

/**
* A utility method to create a {@link CompletableFuture} with cancellation support.
*
Expand Down
Loading