private Object timedGet ( long nanos ) throws TimeoutException { if ( Thread . interrupted ( ) ) return null ; if ( nanos > 0L ) { long d = System . nanoTime ( ) + nanos ; long deadline = ( d == 0L ) ? 1L : d ; // avoid 0 Signaller q = null ; boolean queued = false ; Object r ; while ( ( r = result ) == null ) { // similar to untimed, without spins if ( q == null ) q = new Signaller ( true , nanos , deadline ) ; else if ( ! queued ) queued = tryPushStack ( q ) ; else if ( q . nanos <= 0L ) break ; else { try { ForkJoinPool . managedBlock ( q ) ; } catch ( InterruptedException ie ) { q . interrupted = true ; } if ( q . interrupted ) break ; } } if ( q != null ) q . thread = null ; if ( r != null ) postComplete ( ) ; else cleanStack ( ) ; if ( r != null || ( q != null && q . interrupted ) ) return r ; } throw new TimeoutException ( ) ; }
Returns raw result after waiting or null if interrupted or throws TimeoutException on timeout .