public static < T > T awaitOrCancel ( RedisFuture < T > cmd , long timeout , TimeUnit unit ) { try { if ( ! cmd . await ( timeout , unit ) ) { cmd . cancel ( true ) ; throw ExceptionFactory . createTimeoutException ( Duration . ofNanos ( unit . toNanos ( timeout ) ) ) ; } return cmd . get ( ) ; } catch ( RuntimeException e ) { throw e ; } catch ( ExecutionException e ) { if ( e . getCause ( ) instanceof RedisCommandExecutionException ) { throw ExceptionFactory . createExecutionException ( e . getCause ( ) . getMessage ( ) , e . getCause ( ) ) ; } if ( e . getCause ( ) instanceof RedisCommandTimeoutException ) { throw new RedisCommandTimeoutException ( e . getCause ( ) ) ; } throw new RedisException ( e . getCause ( ) ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; throw new RedisCommandInterruptedException ( e ) ; } catch ( Exception e ) { throw ExceptionFactory . createExecutionException ( null , e ) ; } }
Wait until futures are complete or the supplied timeout is reached . Commands are canceled if the timeout is reached but the command is not finished .