@Override public boolean isCancelled() { return isCancelledState(state); }
@Override public boolean isCancelled() { return isCancelledState(state); }
private static <V> V getResult(Object state) { if (isCancelledState(state)) { return null; } if (!isDoneState(state)) { return null; } if (state instanceof Throwable) { sneakyThrow((Throwable) state); } return (V) state; }
private static <V> V getResult(Object state) { if (isCancelledState(state)) { return null; } if (!isDoneState(state)) { return null; } if (state instanceof Throwable) { sneakyThrow((Throwable) state); } return (V) state; }
Object currentState = this.state; if (isCancelledState(currentState)) { throw new CancellationException();
Object currentState = this.state; if (isCancelledState(currentState)) { throw new CancellationException();
@Override public void andThen(ExecutionCallback<V> callback, Executor executor) { isNotNull(callback, "callback"); isNotNull(executor, "executor"); for (; ; ) { Object currentState = this.state; if (isCancelledState(currentState)) { return; } if (isDoneState(currentState)) { runAsynchronous(callback, executor, currentState); return; } ExecutionCallbackNode newState = new ExecutionCallbackNode<V>(callback, executor, (ExecutionCallbackNode) currentState); if (STATE.compareAndSet(this, currentState, newState)) { // we have successfully scheduled the callback. return; } // we failed to update the state. This can mean 2 things: // either a result was set, which we'll see when retrying this loop // or a different thread also called andThen, which we'll deal with when we retry the loop. } }
@Override public void andThen(ExecutionCallback<V> callback, Executor executor) { isNotNull(callback, "callback"); isNotNull(executor, "executor"); for (; ; ) { Object currentState = this.state; if (isCancelledState(currentState)) { return; } if (isDoneState(currentState)) { runAsynchronous(callback, executor, currentState); return; } ExecutionCallbackNode newState = new ExecutionCallbackNode<V>(callback, executor, (ExecutionCallbackNode) currentState); if (STATE.compareAndSet(this, currentState, newState)) { // we have successfully scheduled the callback. return; } // we failed to update the state. This can mean 2 things: // either a result was set, which we'll see when retrying this loop // or a different thread also called andThen, which we'll deal with when we retry the loop. } }