public static < T > T waitForResult ( String description , Supplier < T > operation , WaitForOptions options ) throws InterruptedException , TimeoutException { T t ; long start = System . currentTimeMillis ( ) ; int interval = options . getInterval ( ) ; int timeout = options . getTimeoutMs ( ) ; while ( ( t = operation . get ( ) ) == null ) { if ( timeout != WaitForOptions . NEVER && System . currentTimeMillis ( ) - start > timeout ) { throw new TimeoutException ( "Timed out waiting for " + description + " options: " + options ) ; } Thread . sleep ( interval ) ; } return t ; }
Waits for an operation to return a non - null value with a specified timeout .