Class SettablePromise<T>

java.lang.Object
io.activej.promise.AbstractPromise<T>
io.activej.promise.SettablePromise<T>
Type Parameters:
T - result type
All Implemented Interfaces:
AsyncComputation<T>, Callback<T>, Promise<T>, SettableCallback<T>

public final class SettablePromise<T> extends AbstractPromise<T> implements SettableCallback<T>
Represents a Promise which can be completed or completedExceptionally manually at once or later in the future.

Can be used as root Promise to start execution of chain of Promises or when you want wrap your actions in Promise.

  • Constructor Details

    • SettablePromise

      public SettablePromise()
  • Method Details

    • set

      public void set(T result, @Nullable @Nullable Exception e)
      Accepts the provided values and performs this operation on them. If the Exception e is null, provided result will be set to this SettablePromise.

      Otherwise, Exception e will be set.

      Specified by:
      set in interface SettableCallback<T>
      Parameters:
      result - a value to be set to this SettablePromise if e is null
      e - a Exception, which will be set to this SettablePromise if not null
    • set

      public void set(T result)
      Sets the result of this SettablePromise and completes it. AssertionError is thrown when you try to set result for an already completed Promise.
      Specified by:
      set in interface SettableCallback<T>
    • setException

      public void setException(Exception e)
      Sets exception and completes this SettablePromise exceptionally. AssertionError is thrown when you try to set exception for an already completed Promise.
      Specified by:
      setException in interface SettableCallback<T>
      Parameters:
      e - exception
    • trySet

      public boolean trySet(T result, @Nullable @Nullable Exception e)
      Tries to set result or exception for this SettablePromise if it is not completed yet. Otherwise, does nothing.
      Specified by:
      trySet in interface SettableCallback<T>
    • trySet

      public boolean trySet(T result)
      Tries to set provided result for this SettablePromise if it is not completed yet. Otherwise, does nothing.
      Specified by:
      trySet in interface SettableCallback<T>
    • trySetException

      public boolean trySetException(Exception e)
      Tries to set provided e exception for this SettablePromise if it is not completed yet. Otherwise, does nothing.
      Specified by:
      trySetException in interface SettableCallback<T>
    • describe

      public String describe()
      Overrides:
      describe in class AbstractPromise<T>