in protonj2-client/src/main/java/org/apache/qpid/protonj2/client/futures/BalancedClientFuture.java [55:97]
public V get(long amount, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
if (isNotComplete() && amount > 0) {
final long timeout = unit.toNanos(amount);
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 {
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();
}
}