| 397 | } |
| 398 | |
| 399 | @SuppressWarnings("unchecked") |
| 400 | @Override |
| 401 | public final T get(final Duration timeout) throws CheckedFutureException { |
| 402 | final Object curr = state; |
| 403 | if (curr instanceof Future && !(curr instanceof Continuation) && ((Future<T>) curr).isDefined()) |
| 404 | return ((Future<T>) curr).get(Duration.ZERO); |
| 405 | else if (curr instanceof LinkedContinuation && ((LinkedContinuation<?, T>) curr).isDefined()) |
| 406 | return ((LinkedContinuation<?, T>) curr).get(Duration.ZERO); |
| 407 | else { |
| 408 | join(timeout); |
| 409 | return ((Future<T>) state).get(Duration.ZERO); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | // Inpired by Scala Future's CompletionLatch |
| 414 | private static final class ReleaseOnRunLatch extends AbstractQueuedSynchronizer implements Runnable { |