class CompletableResult<T> implements AsyncResult<T> {

    static final int RUNNING = 1;
    static final int FAILED = 2;
    static final int COMPLETED = 3;

    final Object lock;
    final AsyncCallback<T> callback;

    volatile int state = RUNNING;
    T value;
    Exception exception;

    CompletableResult(AsyncCallback<T> callback) {
      this.lock = new Object();
      this.callback = callback;
    }

    boolean hasCallback() {
      return callback != null;
    }

    /**
     * Sets the value from successful execution and executes callback if available. Notifies any
     * thread waiting for completion.
     *
     * @param value value of the evaluated task
     */
    void setValue(T value) {
      this.value = value;
      this.state = COMPLETED;
      if (hasCallback()) {
        callback.onComplete(value);
      }
      synchronized (lock) {
        lock.notifyAll();
      }
    }

    /**
     * Sets the exception from failed execution and executes callback if available. Notifies any
     * thread waiting for completion.
     *
     * @param exception exception of the failed task
     */
    void setException(Exception exception) {<FILL_FUNCTION_BODY>}

    @Override
    public boolean isCompleted() {
      return state > RUNNING;
    }

    @Override
    public T getValue() throws ExecutionException {
      if (state == COMPLETED) {
        return value;
      } else if (state == FAILED) {
        throw new ExecutionException(exception);
      } else {
        throw new IllegalStateException("Execution not completed yet");
      }
    }

    @Override
    public void await() throws InterruptedException {
      synchronized (lock) {
        while (!isCompleted()) {
          lock.wait();
        }
      }
    }
  }

      this.exception = exception;
      this.state = FAILED;
      if (hasCallback()) {
        callback.onError(exception);
      }
      synchronized (lock) {
        lock.notifyAll();
      }
    
<no_super_class>