/*
 * Copyright 2014 Timothy Brooks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package net.uncontended.precipice.concurrent;

import net.uncontended.precipice.Status;

import java.util.concurrent.TimeUnit;

public interface ResilientPromise<T> {
    /**
     * Deliver the result to this promise. If the promise has already been completed,
     * this method will return false.
     *
     * @param result the result of the promise
     * @return a boolean indicating if the result was successfully set.
     */
    boolean deliverResult(T result);

    /**
     * Deliver an error to this promise. If the promise has already been completed,
     * this method will return false.
     *
     * @param error the error to deliver
     * @return a boolean indicating if the result was successfully set.
     */
    boolean deliverError(Throwable error);

    /**
     * Block on this promise being completed.
     *
     * @throws InterruptedException
     */
    void await() throws InterruptedException;

    boolean await(long timePeriod, TimeUnit unit) throws InterruptedException;

    /**
     * Block on this promise being completed and return the result. If promise is
     * not successfully completed, this will return null.
     *
     * @return T the result of the promise.
     * @throws InterruptedException
     */
    T awaitResult() throws InterruptedException;

    T getResult();

    Throwable getError();

    Status getStatus();

    boolean setTimedOut();

    boolean isSuccessful();

    boolean isDone();

    boolean isError();

    boolean isTimedOut();

}

@@ -1003,36 +1003,41 @@
 as successfully 
-set.
+delivered
 %0A     */%0A    boo
@@ -1280,38 +1280,37 @@
 dicating if the 
-result
+error
  was successfull
@@ -1315,12 +1315,17 @@
 lly 
-set.
+delivered
 %0A   
@@ -1802,17 +1802,16 @@
  promise
-.
 %0A     * 
@@ -1905,179 +1905,1531 @@
     
-T getResult();%0A%0A    Throwable getError();%0A%0A    Status getStatus();%0A%0A    boolean setTimedOut();%0A%0A    boolean isSuccessful();%0A%0A    boolean isDone();%0A%0A    boolean isError();%0A
+/**%0A     * Return any result that has been delivered. If promise is not successfully completed%0A     * or is still pending, this will return null.%0A     *%0A     * @return T the result of the promise%0A     */%0A    T getResult();%0A%0A    /**%0A     * Return any error that has been delivered. If action did not error or is still pending,%0A     * this will return null.%0A     *%0A     * @return Throwable the error of the promise%0A     */%0A    Throwable getError();%0A%0A    /**%0A     * Return the status of the promise.%0A     *%0A     * @return Status the status of the promise%0A     */%0A    Status getStatus();%0A%0A    /**%0A     * Set the promise %7B@link Status%7D to timeout. If the promise has already been completed,%0A     * this method will return false.%0A     *%0A     * @return a boolean indicating if the status was successfully set to timeout%0A     */%0A    boolean setTimedOut();%0A%0A    /**%0A     * Indicate if the %7B@link Status%7D of the promise is successful.%0A     *%0A     * @return boolean indicating if the status is successful%0A     */%0A    boolean isSuccessful();%0A%0A    /**%0A     * Indicate if the %7B@link Status%7D of the promise is not pending.%0A     *%0A     * @return boolean indicating if the promise is not pending%0A     */%0A    boolean isDone();%0A%0A    /**%0A     * Indicate if the %7B@link Status%7D of the promise is error.%0A     *%0A     * @return boolean indicating if the status is error%0A     */%0A    boolean isError();%0A%0A    /**%0A     * Indicate if the %7B@link Status%7D of the promise is timeout.%0A     *%0A     * @return boolean indicating if the status is timeout%0A     */
 %0A   

Add documentation to promise