protected final <S> CompletableFuture<S> executeSubTask(
      final Supplier<CompletableFuture<S>> subTask) {
    synchronized (result) {
      if (!isCancelled()) {
        final CompletableFuture<S> subTaskFuture = subTask.get();
        subTaskFutures.add(subTaskFuture);
        subTaskFuture.whenComplete((r, t) -> subTaskFutures.remove(subTaskFuture));
        return subTaskFuture;
      } else {
        return CompletableFuture.failedFuture(new CancellationException());
      }
    }
  }
Utility for executing completable futures that handles cleanup if this EthTask is cancelled.

@param subTask a subTask to execute
@param <S> the type of data returned from the CompletableFuture
@return The completableFuture that was executed
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractEthTask.java