public function waitUntil(int $timeoutSeconds, callable $callback, bool $throwOnFailure = true)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException('Given callback is not a valid callable');
        }

        $start = time();
        $end = $start + $timeoutSeconds;

        $lastInternalExceptionMessage = '';

        do {
            try {
                $result = $callback($this);

                if ($result) {
                    return $result;
                }
            } catch (Exception $e) {
                $lastInternalExceptionMessage = $e->getMessage();
            }
            usleep(250 * 1000);
        } while (time() < $end);

        if ($throwOnFailure) {
            throw new Exception('Spin function did not return in time. Internal exception:' . $lastInternalExceptionMessage);
        }
    }
public function waitUntil(int $timeoutSeconds, callable $callback, bool $throwOnFailure = true)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException('Given callback is not a valid callable');
        }

        $start = time();
        $end = $start + $timeoutSeconds;

        $lastInternalExceptionMessage = '';

        do {
            try {
                $result = $callback($this);

                if ($result) {
                    return $result;
                }
            } catch (Exception $e) {
                $lastInternalExceptionMessage = $e->getMessage();
            }
            usleep(250 * 1000);
        } while (time() < $end);

        if ($throwOnFailure) {
            throw new Exception('Spin function did not return in time. Internal exception:' . $lastInternalExceptionMessage);
        }
    }
public function waitUntil ( int $ timeoutSeconds , callable $ callback , bool $ throwOnFailure = true ) { if ( ! is_callable ( $ callback ) ) { throw new \ InvalidArgumentException ( 'Given callback is not a valid callable' ) ; } $ start = time ( ) ; $ end = $ start + $ timeoutSeconds ; $ lastInternalExceptionMessage = '' ; do { try { $ result = $ callback ( $ this ) ; if ( $ result ) { return $ result ; } } catch ( Exception $ e ) { $ lastInternalExceptionMessage = $ e -> getMessage ( ) ; } usleep ( 250 * 1000 ) ; } while ( time ( ) < $ end ) ; if ( $ throwOnFailure ) { throw new Exception ( 'Spin function did not return in time. Internal exception:' . $ lastInternalExceptionMessage ) ; } }
Waits no longer than specified timeout for the given condition to be true.

@param int $timeoutSeconds Timeout
@param callable Condition to verify
@param bool $throwOnFailure Whether Exception should be thrown when timeout is exceeded

@return mixed

@throws Exception If $throwOnFailure is true and timeout exceeded
Waits no longer than specified timeout for the given condition to be true .