@ Nullable final T blockingGet ( long timeout , TimeUnit unit ) { if ( Schedulers . isInNonBlockingThread ( ) ) { throw new IllegalStateException ( "block()/blockFirst()/blockLast() are blocking, which is not supported in thread " + Thread . currentThread ( ) . getName ( ) ) ; } if ( getCount ( ) != 0 ) { try { if ( ! await ( timeout , unit ) ) { dispose ( ) ; throw new IllegalStateException ( "Timeout on blocking read for " + timeout + " " + unit ) ; } } catch ( InterruptedException ex ) { dispose ( ) ; RuntimeException re = Exceptions . propagate ( ex ) ; //this is ok, as re is always a new non-singleton instance re . addSuppressed ( new Exception ( "#block has been interrupted" ) ) ; throw re ; } } Throwable e = error ; if ( e != null ) { RuntimeException re = Exceptions . propagate ( e ) ; //this is ok, as re is always a new non-singleton instance re . addSuppressed ( new Exception ( "#block terminated with an error" ) ) ; throw re ; } return value ; }
Block until the first value arrives and return it otherwise return null for an empty source and rethrow any exception .