default <T> T waitForFuture(
        Future<T> future,
        long deadlineNs
    ) throws TimeoutException, InterruptedException, ExecutionException  {
        TimeoutException timeoutException = null;
        while (true) {
            long nowNs = nanoseconds();
            if (deadlineNs <= nowNs) {
                throw (timeoutException == null) ? new TimeoutException() : timeoutException;
            }
            long deltaNs = deadlineNs - nowNs;
            try {
                return future.get(deltaNs, TimeUnit.NANOSECONDS);
            } catch (TimeoutException t) {
                timeoutException = t;
            }
        }
    }
Wait for a future to complete, or time out.

@param future        The future to wait for.
@param deadlineNs    The time in the future, in monotonic nanoseconds, to time out.
@return              The result of the future.
@param <T>           The type of the future.
clients/src/main/java/org/apache/kafka/common/utils/Time.java