@Override
    public T get(long timeout, TimeUnit unit)
            throws InterruptedException, TimeoutException {
        synchronized (this) {
            if (completed) {
                return results == null || results.isEmpty()
                    ? null
                    : results.get(0);
            }
            wait(unit.toMillis(timeout));
        }
        if (completed) {
            return results == null || results.isEmpty()
                ? null
                : results.get(0);
        }
        throw new TimeoutException();
    }
@ Override public T get ( long timeout , TimeUnit unit ) throws InterruptedException , TimeoutException { synchronized ( this ) { if ( completed ) { return results == null || results . isEmpty ( ) ? null : results . get ( 0 ) ; } wait ( unit . toMillis ( timeout ) ) ; } if ( completed ) { return results == null || results . isEmpty ( ) ? null : results . get ( 0 ) ; } throw new TimeoutException ( ) ; }
Causes the invoking thread to wait until the processing of the
event has been completed (see {@link #isDone()}) or the given
timeout has expired and returns the first (or only) result.

@return the result
@see java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)