code: public boolean await(long maxWait, TimeUnit timeUnit) throws Exception
      {
          boolean hasWait = (timeUnit != null);
          long startMs = System.currentTimeMillis();
          for (;;)
          {
              String status = client.command().status(queryId).invoke().get().getStatus();
              if (status.equalsIgnoreCase(STATUS_DONE))
              {
                  break;
              }
              if (!status.equalsIgnoreCase(STATUS_RUNNING) && !status.equalsIgnoreCase(STATUS_WAITING))
              {
                  throw new Exception(String.format("Bad status for query %s: %s", queryId, status));
              }
  
              if (hasWait)
              {
                  long elapsedMs = System.currentTimeMillis() - startMs;
                  if (elapsedMs >= timeUnit.toMillis(maxWait))
                  {
                      return false;
                  }
              }
              Thread.sleep(pollMs.get());
          }
          return true;
      }
docs: Await up to a maximum time for the result
  
  @param maxWait max wait time
  @param timeUnit time unit
  @return true if the result is ready, false if not or time has run out
  @throws Exception errors