code: public boolean waitForCompletion(long duration, TimeUnit timeUnit) throws InterruptedException {
      synchronized (lock) {
        if (!isCompleted()) {
          lock.wait(timeUnit.toMillis(duration));
        }
        return isCompleted();
      }
    }
docs: Blocks until the task is complete or times out.
  @return {@code true} if the task completed (has a result, an error, or was cancelled).
  {@code false} otherwise.