code: public <T> void register(CompletableFuture<T> future) {
          if (future.isDone()) {
              // Nothing to do.
              return;
          }
  
          boolean autoCancel = false;
          synchronized (this.futures) {
              Preconditions.checkNotNull(future, "future");
              if (this.cancellationRequested) {
                  autoCancel = true;
              } else {
                  this.futures.add(future);
              }
          }
  
          if (autoCancel) {
              // CancellationToken is already cancelled. Don't register anything, yet cancel the future we're given.
              future.cancel(true);
              return;
          }
  
          // Cleanup once the future is completed.
          future.whenComplete((r, ex) -> {
              synchronized (this.futures) {
                  this.futures.remove(future);
              }
          });
      }
docs: Registers the given Future to the token.
  
  @param future The Future to register.
  @param <T>    Return type of the future.