public boolean waitUntilDone(Duration timeout) throws InterruptedException {
        synchronized (this) {
            if (completed) {
                return true;
            }
            if (timeout.isZero()) {
                while (!completed) {
                    wait();
                }
            } else {
                wait(timeout.toMillis());
            }
            return completed;
        }
    }
Waits until visiting is done, or the given timeout (in ms) expires.
Will wait forever if timeout is 0.

@param timeout Maximum time duration to wait before returning.
@return True if visiting is done (either by error or success), false if session has timed out.
@throws InterruptedException If an interrupt signal was received while waiting.
documentapi/src/main/java/com/yahoo/documentapi/VisitorControlHandler.java