in protonj2-client/src/main/java/org/apache/qpid/protonj2/client/futures/ProgressiveClientFuture.java [59:111]
public V get(long amount, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
if (isNotComplete() && amount > 0) {
final long timeout = unit.toNanos(amount);
long maxParkNanos = timeout / 8;
maxParkNanos = maxParkNanos > 0 ? maxParkNanos : timeout;
final long tinyParkNanos = Math.min(maxParkNanos, TINY_PARK_NANOS);
final long smallParkNanos = Math.min(maxParkNanos, SMALL_PARK_NANOS);
final long startTime = System.nanoTime();
int idleCount = 0;
while (isNotComplete()) {
final long elapsed = System.nanoTime() - startTime;
final long diff = elapsed - timeout;
if (diff >= 0) {
throw new TimeoutException("Timed out waiting for completion");
} else if (idleCount < SPIN_COUNT) {
idleCount++;
} else if (idleCount < YIELD_COUNT) {
Thread.yield();
idleCount++;
} else if (idleCount < TINY_PARK_COUNT) {
LockSupport.parkNanos(tinyParkNanos);
idleCount++;
} else if (idleCount < SMALL_PARK_COUNT) {
LockSupport.parkNanos(smallParkNanos);
idleCount++;
} else {
synchronized (this) {
if (isComplete()) {
break;
} else if (getState() < COMPLETING) {
waiting++;
try {
wait(-diff / 1000000, (int) (-diff % 1000000));
} catch (InterruptedException e) {
Thread.interrupted();
throw e;
} finally {
waiting--;
}
}
}
}
}
}
if (error != null) {
throw error;
} else {
return getResult();
}
}