T waitFor()

in module/geb-waiting/src/main/groovy/geb/waiting/Wait.groovy [101:132]


    <T> T waitFor(Closure<T> block) {
        def timeoutThreshold = timeoutThresholdFromNow()
        def pass
        def thrown = null

        try {
            pass = block()
        } catch (Throwable e) {
            pass = new UnknownWaitForEvaluationResult(e)
            thrown = e
        }

        def timedOut = timeoutThreshold - System.nanoTime() <= 0
        while (!pass && !timedOut) {
            sleepForRetryInterval()
            try {
                pass = block()
                thrown = null
            } catch (Throwable e) {
                pass = new UnknownWaitForEvaluationResult(e)
                thrown = e
            } finally {
                timedOut = timeoutThreshold - System.nanoTime() <= 0
            }
        }

        if (!pass && timedOut && !quiet) {
            throw new WaitTimeoutException(this, thrown, pass)
        }

        pass as T
    }