use of co.paralleluniverse.fibers.RuntimeExecutionException in project quasar by puniverse.
the class Val method get.
/**
* Returns the delayed value, blocking until it has been set, but no longer than the given timeout.
*
* @param timeout The maximum duration to block waiting for the value to be set.
* @param unit The time unit of the timeout value.
* @return the value
* @throws TimeoutException if the timeout expires before the value is set.
* @throws InterruptedException
*/
@Override
@Suspendable
public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
try {
final SimpleConditionSynchronizer s = sync;
if (s != null) {
Object token = s.register();
try {
final long start = System.nanoTime();
long left = unit.toNanos(timeout);
final long deadline = start + left;
for (int i = 0; sync != null; i++) {
s.awaitNanos(i, left);
if (sync == null)
break;
left = deadline - System.nanoTime();
if (left <= 0)
throw new TimeoutException();
}
} finally {
s.unregister(token);
}
}
if (t != null)
throw t instanceof CancellationException ? (CancellationException) t : new RuntimeExecutionException(t);
return value;
} catch (SuspendExecution e) {
throw new AssertionError(e);
}
}
Aggregations