Await up to a maximum time for the result

@param maxWait max wait time
@param timeUnit time unit
@return the result
@throws Exception errors
490059
public ResultValue awaitResult(long maxWait, TimeUnit timeUnit) throws Exception
    {
        if (!await(maxWait, timeUnit))
        {
            throw new TimeoutException();
        }
        return getResultValue();
    }
187221
public Retryer<R> randomWait(final long minimum, final long maximum) {
        checkArgument(minimum >= 0, "minimum must be >= 0 but is %d", minimum);
        checkArgument(maximum > minimum, "maximum must be > minimum but maximum is %d and minimum is", maximum, minimum);
        
        final Random random = new Random();
        return withWaitStrategy(new WaitStrategy() {
            @Override public long computeSleepTime(int previousAttemptNumber, long delaySinceFirstAttemptInMillis) {
                long t = Math.abs(random.nextLong()) % (maximum - minimum);
                return t + minimum;
            }
        });
    }
368216
public void await(long weight, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        barrier.await(weight, timeout, unit);
    }
128350
private boolean waitForAdd(long waitStart, long maxWait) throws InterruptedException {
        while (this.size == 0) {
            if (!waitOnCondition(this.notEmpty, maxWait, waitStart)) {
                return false;
            }
        }

        return true;
    }
879249
public Reason wait(T waiter, long timeout, TimeUnit unit)
    {
        if (list == null)
        {
            return Reason.Release;
        }
        try
        {
            Locks.locked(lock, waiter, (w)->{list.add(w);});
            if (semaphore.tryAcquire(timeout, unit))
            {
                return Reason.Release;
            }
            else
            {
                list.remove(waiter);
                return Reason.Timeout;
            }
        }
1279933
public boolean waitForCompletion(long duration, TimeUnit timeUnit) throws InterruptedException {
    synchronized (lock) {
      if (!isCompleted()) {
        lock.wait(timeUnit.toMillis(duration));
      }
      return isCompleted();
    }
  }
891174
@Override
    public synchronized Response get(long timeout, TimeUnit unit)
            throws InterruptedException, ExecutionException, TimeoutException {
        long now = System.currentTimeMillis();
        long mills = unit.toMillis(timeout);
        long toWait = mills;
        if (this.completed) {
            return this.getResult();
        } else if (toWait <= 0) {
            throw new TimeoutException("Timeout is smaller than 0.");
        } else {
            for (;;) {
                wait(toWait);
                if (this.completed) {
                    return this.getResult();
                }
                long gap = System.currentTimeMillis() - now;
                toWait = toWait - gap;
                if (toWait <= 0) {
                    throw new TimeoutException();
                }
            }
        }
    }
1253277
@Override
    public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        if (this.m_coordinationLatch.await(timeout, unit) == false) {
            throw new TimeoutException();
        }

        if (m_pendingException != null) {
            throw m_pendingException;
        }

        return m_defaultFuture.get(timeout, unit);
    }
698486
private Object waitForResult(long timeoutMillis)
                    throws ExecutionException, InterruptedException, TimeoutException, RemoteException { // F16043
        final boolean isTraceOn = svLogger.isLoggable(Level.FINER);
        if (isTraceOn)
            svLogger.entering(CLASS_NAME, "waitForResult", Long.valueOf(timeoutMillis));

        long begin = System.nanoTime();
        // The nanoTime updated before every call to
        // RemoteAsyncResultExtended.waitForResult.
        long beginLastAttempt = begin;
        // The nanoTime when we should stop waiting altogether.  This value is
        // only used if timeout is non-zero.
        long end = begin + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);

        // True if the client ORB has ever thrown a NO_RESPONSE.
        boolean noResponse = false;
        // The waitTime argument for the next call to
        // RemoteAsyncResultExtended.waitForResult.
        long waitTimeMillis = timeoutMillis;
        // The maximum value for waitTimeMillis.  This value is lazily
        // initialized when a NO_RESPONSE occurs.
        long maxWaitTimeMillis = -1;

        for (;;) {
            if (isTraceOn)
                svLogger.entering(CLASS_NAME, "waitForResult", "waiting " + waitTimeMillis);

            Object[] resultArray;
            try {
                resultArray = stubWaitForResult((Stub) ivServer, waitTimeMillis);
            } catch (RemoteException ex) {
                Throwable cause = ex.getCause();

                // If this is the first NO_RESPONSE, then try again with a shorter
                // server-side wait time.  For subsequent NO_RESPONSE, assume there
                // is a connection issue and rethrow the exception.
                if (cause instanceof NO_RESPONSE && !noResponse) {
                    if (isTraceOn)
                        svLogger.logp(Level.FINER, CLASS_NAME, "waitForResult", "retrying", cause);
                    resultArray = null;
                    noResponse = true;
                } else {
                    if (isTraceOn)
                        svLogger.exiting(CLASS_NAME, "waitForResult", ex);
                    throw ex;
                }
            }

            if (resultArray != null) {
                if (isTraceOn)
                    svLogger.exiting(CLASS_NAME, "waitForResult", "result");
                return resultArray[0];
            }

            // Either the client ORB or the server timed us out.  Choose a lower
            // waitTimeMillis and then try again.

            long now = System.nanoTime();

            if (timeoutMillis > 0) {
                long remainingMillis = TimeUnit.NANOSECONDS.toMillis(end - now);
                if (remainingMillis <= 0) {
                    if (isTraceOn)
                        svLogger.exiting(CLASS_NAME, "waitForResult", "timeout");
                    throw new TimeoutException();
                }

                waitTimeMillis = remainingMillis;
            }

            if (noResponse) {
                if (maxWaitTimeMillis == -1) {
                    // For the first NO_RESPONSE, set maximum server wait time for
                    // all subsequent requests based on how long the ORB actually
                    // waited before timing out this request.  Back off a little bit
                    // to give time for the server to respond.
                    long actualWaitTimeMillis = TimeUnit.NANOSECONDS.toMillis(now - beginLastAttempt);
                    maxWaitTimeMillis = Math.max(MIN_ASYNC_RESULT_NO_RESPONSE_WAIT_TIME,
                                                 actualWaitTimeMillis - AsyncResultNoResponseBackoff);
                }

                if (timeoutMillis == 0) {
                    waitTimeMillis = maxWaitTimeMillis;
                } else {
                    waitTimeMillis = Math.min(waitTimeMillis, maxWaitTimeMillis);
                }
            }

            beginLastAttempt = now;
        }
    }
974361
public PollingWait pollEvery(long timeAmount, @Nonnull TimeUnit timeUnit) {
        if (timeAmount <= 0) {
            throw new IllegalArgumentException("Invalid timeAmount: " + timeAmount + " -- must be greater than 0");
        }
        pollIntervalMillis = timeUnit.toMillis(timeAmount);
        return this;
    }
458678
public void await(Event event, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        long timestamp = getTimestamp(event);
        try {
            lock.lockInterruptibly();
            single(timestamp);
            while (isPermit(event, timestamp) == false) {
                condition.await(timeout, unit);
            }
        } finally {
            lock.unlock();
        }
    }
1336009
protected TimeoutId requestTimeout(final long delay, final TimeUnit unit) {
        return requestTimeout(delay, unit, null, null);
    }
784493
public static ConcurrentLimitRule of(int concurrentLimit, TimeUnit timeOutUnit, long timeOut) {
        requireNonNull(timeOutUnit, "time out unit can not be null");
        return new ConcurrentLimitRule(concurrentLimit, timeOutUnit.toMillis(timeOut));
    }
216517
public void waitDone() throws ResponseTimeoutException,
            InvalidResponseException {
        lock.lock();
        try {
            if (!isDoneResponse()) {
                try {
                    condition.await(timeout, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new RuntimeException("Interrupted");
                }
            }
            
            if (illegalResponseException != null) {
                throw illegalResponseException;
            }
            
            if (!isDoneResponse()) {
                throw new ResponseTimeoutException("No response after " + timeout
                        + " millis");
            }
        } finally {
            lock.unlock();
        }
    }
306986
public static <T> CompletableFuture<T> orTimeout(CompletableFuture<T> future, long timeout, TimeUnit timeUnit) {
		return orTimeout(future, timeout, timeUnit, Executors.directExecutor());
	}
1228443
public boolean awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
        boolean result = completed.await(timeout, timeUnit);
        throwFirstError();
        return result;
    }
58805
@Override
	public long getDelay(TimeUnit unit) {

		long next = TimeUnit.MILLISECONDS.convert(getDelayToNextExecutionInMillis(), unit);

		logger.info("{} ms until start of task {}", new Object[] { next, name });

		return next;
	}