code: public static <T> T waitForResult(String description, Supplier<T> operation,
        WaitForOptions options) throws InterruptedException, TimeoutException {
      T t;
      long start = System.currentTimeMillis();
      int interval = options.getInterval();
      int timeout = options.getTimeoutMs();
      while ((t = operation.get()) == null) {
        if (timeout != WaitForOptions.NEVER && System.currentTimeMillis() - start > timeout) {
          throw new TimeoutException("Timed out waiting for " + description + " options: " + options);
        }
        Thread.sleep(interval);
      }
      return t;
    }
docs: Waits for an operation to return a non-null value with a specified timeout.
  
  @param description the description of this operation
  @param operation the operation
  @param options the options to use
  @param <T> the type of the return value
  @throws TimeoutException if the function times out while waiting to get a non-null value
  @return the first non-null value generated by the operation