Class CompleteExceptionallyPromise<T>

java.lang.Object
io.activej.promise.CompleteExceptionallyPromise<T>
All Implemented Interfaces:
AsyncComputation<T>, Promise<T>

public final class CompleteExceptionallyPromise<T> extends Object implements Promise<T>
Represents a Promise which is completed with an exception.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Ensures that Promise completes asynchronously: if this Promise is already completed, its completion will be posted to the next reactor tick.
    both(Promise<?> other)
    Returns a new Promise when both this and provided other Promises complete.
    <U, V> Promise<V>
    combine(Promise<? extends U> other, io.activej.common.function.BiFunctionEx<? super T,? super U,? extends V> fn)
    Returns a new Promise that, when this and the other given Promise both complete, is executed with the two results as arguments to the supplied function.
    either(Promise<? extends T> other)
    Returns the Promise which was completed first.
     
     
    io.activej.common.collection.Try<T>
     
    boolean
     
    boolean
     
    boolean
     
    <U> Promise<U>
    map(io.activej.common.function.BiFunctionEx<? super T,Exception,? extends U> fn)
    Returns a new Promise which is obtained by mapping a result and an exception of this promise to some other value.
    <U> Promise<U>
    map(io.activej.common.function.FunctionEx<? super T,? extends U> fn)
    Returns a new Promise which is obtained by mapping a result of this promise to some other value.
    <U> Promise<U>
    map(io.activej.common.function.FunctionEx<? super T,? extends U> fn, io.activej.common.function.FunctionEx<Exception,? extends U> exceptionFn)
    Returns a new Promise which is obtained by mapping either a result or an exception of this promise to some other values.
    mapException(io.activej.common.function.FunctionEx<Exception,Exception> exceptionFn)
    Returns a new Promise which is obtained by mapping an exception of this promise to some other exception.
    <E extends Exception>
    Promise<T>
    mapException(Class<E> clazz, io.activej.common.function.FunctionEx<? super E,? extends Exception> exceptionFn)
    Returns a new Promise which is obtained by mapping an exception of this promise to some other exception.
    void
    next(NextPromise<? super T,?> cb)
    Calls a callback after this promise is completed, passing both a result and an exception of a promise to the callback.
    subscribe(Callback<? super T> cb)
     
    <U> Promise<U>
    Returns a new Promise which is obtained by mapping a result and an exception of this promise to some other promise.
    <U> Promise<U>
    then(AsyncFunctionEx<? super T,U> fn)
    Returns a new Promise which is obtained by mapping a result of this promise to some other promise.
    <U> Promise<U>
    then(AsyncFunctionEx<? super T,U> fn, AsyncFunctionEx<Exception,U> exceptionFn)
    Returns a new Promise which is obtained by mapping either a result or an exception of this promise to some other promises.
    <U> Promise<U>
    Returns a new Promise which is obtained by calling a provided supplier of a new promise.
    <U> Promise<U>
    thenCallback(CallbackBiFunctionEx<? super T,@Nullable Exception,U> fn)
     
    <U> Promise<U>
     
    <U> Promise<U>
     
    <U> Promise<U>
     
    Wraps Promise into CompletableFuture.
    Promise<io.activej.common.collection.Try<T>>
    Returns Promise that always completes successfully with result or exception wrapped in Try.
    Waits for result and discards it.
    whenComplete(io.activej.common.function.BiConsumerEx<? super T,Exception> fn)
    Subscribes given consumer to be executed after this Promise completes (either successfully or exceptionally).
    whenComplete(io.activej.common.function.ConsumerEx<? super T> fn, io.activej.common.function.ConsumerEx<Exception> exceptionFn)
    Subscribes given consumers to be executed after this Promise completes (either successfully or exceptionally).
    whenComplete(io.activej.common.function.RunnableEx action)
    Subscribes given runnable to be executed after this Promise completes (either successfully or exceptionally).
    whenException(io.activej.common.function.ConsumerEx<Exception> fn)
    Subscribes given consumer to be executed after this Promise completes exceptionally.
    whenException(io.activej.common.function.RunnableEx action)
    Subscribes given runnable to be executed after this Promise completes exceptionally.
    whenException(Class<? extends Exception> clazz, io.activej.common.function.RunnableEx action)
    Subscribes given runnable to be executed after this Promise completes exceptionally and an exception of this Promise is an instance of a given exception Class.
    <E extends Exception>
    Promise<T>
    whenException(Class<E> clazz, io.activej.common.function.ConsumerEx<? super E> fn)
    Subscribes given consumer to be executed after this Promise completes exceptionally and an exception of this Promise is an instance of a given exception Class.
    whenResult(io.activej.common.function.ConsumerEx<? super T> fn)
    Subscribes given consumer to be executed after this Promise completes successfully.
    whenResult(io.activej.common.function.RunnableEx action)
    Subscribes given runnable to be executed after this Promise completes successfully and a result of this Promise satisfy a given Predicate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.activej.promise.Promise

    call, cast, cast
  • Constructor Details

    • CompleteExceptionallyPromise

      public CompleteExceptionallyPromise(Exception e)
  • Method Details

    • isComplete

      public boolean isComplete()
      Specified by:
      isComplete in interface Promise<T>
    • isResult

      public boolean isResult()
      Specified by:
      isResult in interface Promise<T>
    • isException

      public boolean isException()
      Specified by:
      isException in interface Promise<T>
    • getResult

      public T getResult()
      Specified by:
      getResult in interface Promise<T>
    • getException

      public Exception getException()
      Specified by:
      getException in interface Promise<T>
    • getTry

      public io.activej.common.collection.Try<T> getTry()
      Specified by:
      getTry in interface Promise<T>
    • map

      public <U> Promise<U> map(io.activej.common.function.FunctionEx<? super T,? extends U> fn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping a result of this promise to some other value. If this promise is completed exceptionally, a mapping function will not be applied.

      A mapping function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      map in interface Promise<T>
      Parameters:
      fn - a function to map the result of this Promise to a new value
      Returns:
      new Promise whose result is the result of function applied to the result of this promise
      See Also:
    • map

      public <U> Promise<U> map(io.activej.common.function.BiFunctionEx<? super T,Exception,? extends U> fn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping a result and an exception of this promise to some other value. If this promise is completed exceptionally, an exception passed to a mapping function is guaranteed to be not null.

      A {bi function} may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      map in interface Promise<T>
      Parameters:
      fn - a function to map a result and an exception of this promise to some other value
      Returns:
      new Promise whose result is the result of function applied to the result and exception of this promise
    • map

      public <U> Promise<U> map(io.activej.common.function.FunctionEx<? super T,? extends U> fn, io.activej.common.function.FunctionEx<Exception,? extends U> exceptionFn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping either a result or an exception of this promise to some other values. If this promise is completed successfully, the first function will be called mapping the result to some other value. Otherwise, second function will be called mapping the exception to some other value.

      Each function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      map in interface Promise<T>
      Parameters:
      fn - a function to map a result of this promise to some other value
      exceptionFn - a function to map an exception of this promise to some other value
      Returns:
      new Promise whose result is the result of either first or second function applied either to a result or an exception of this promise.
    • mapException

      public Promise<T> mapException(io.activej.common.function.FunctionEx<Exception,Exception> exceptionFn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping an exception of this promise to some other exception. The mapping function will be called only if this promise completes exceptionally

      A mapping function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      mapException in interface Promise<T>
      Parameters:
      exceptionFn - a function to map an exception of this promise to some other value
      Returns:
      new Promise whose result is the result of a mapping function applied either to an exception of this promise.
    • mapException

      public <E extends Exception> Promise<T> mapException(Class<E> clazz, io.activej.common.function.FunctionEx<? super E,? extends Exception> exceptionFn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping an exception of this promise to some other exception. The mapping function will be called only if this promise completes with an exception that is an instance of a given Class

      A mapping function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      mapException in interface Promise<T>
      Parameters:
      clazz - an exception class that exception is tested against. A mapping function is applied only if an exception of this promise is an instance of the specified class
      exceptionFn - a function to map an exception of this promise to some other value
      Returns:
      new Promise whose result is the result of a mapping function applied either to an exception of this promise.
    • then

      public <U> Promise<U> then(AsyncFunctionEx<? super T,U> fn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping a result of this promise to some other promise. If this promise is completed exceptionally, a mapping function will not be applied.

      A mapping function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      then in interface Promise<T>
      Parameters:
      fn - a function to map the result of this Promise to a new promise
      Returns:
      new Promise which is the result of function applied to the result of this promise
      See Also:
    • thenCallback

      public <U> Promise<U> thenCallback(CallbackFunctionEx<? super T,U> fn)
      Specified by:
      thenCallback in interface Promise<T>
    • then

      public <U> Promise<U> then(AsyncSupplierEx<U> fn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by calling a provided supplier of a new promise. If this promise is completed exceptionally, a supplier will not be called.

      A supplier may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      then in interface Promise<T>
      Parameters:
      fn - a supplier of a new promise which will be called if this promise completes successfully
    • thenCallback

      public <U> Promise<U> thenCallback(CallbackSupplierEx<U> fn)
      Specified by:
      thenCallback in interface Promise<T>
    • then

      public <U> Promise<U> then(AsyncBiFunctionEx<? super T,Exception,U> fn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping a result and an exception of this promise to some other promise. If this promise is completed exceptionally, an exception passed to a mapping function is guaranteed to be not null.

      A function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      then in interface Promise<T>
      Parameters:
      fn - a function to map a result and an exception of this promise to some other promise
      Returns:
      new Promise which is the result of function applied to the result and exception of this promise
    • thenCallback

      public <U> Promise<U> thenCallback(CallbackBiFunctionEx<? super T,@Nullable Exception,U> fn)
      Specified by:
      thenCallback in interface Promise<T>
    • then

      public <U> Promise<U> then(AsyncFunctionEx<? super T,U> fn, AsyncFunctionEx<Exception,U> exceptionFn)
      Description copied from interface: Promise
      Returns a new Promise which is obtained by mapping either a result or an exception of this promise to some other promises. If this promise is completed successfully, the first function will be called mapping the result to a promise of some other value. Otherwise, second function will be called mapping the exception to a promise of some other value.

      Each function may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      then in interface Promise<T>
      Parameters:
      fn - a function to map a result of this promise to a dofferent promise
      exceptionFn - a function to map an exception of this promise a different promise
      Returns:
      new Promise which is a result of either first or second function applied either to a result or an exception of this promise.
    • thenCallback

      public <U> Promise<U> thenCallback(CallbackFunctionEx<? super T,U> fn, CallbackFunctionEx<Exception,U> exceptionFn)
      Specified by:
      thenCallback in interface Promise<T>
    • whenComplete

      public Promise<T> whenComplete(io.activej.common.function.BiConsumerEx<? super T,Exception> fn)
      Description copied from interface: Promise
      Subscribes given consumer to be executed after this Promise completes (either successfully or exceptionally). Returns a new Promise.

      A consumer may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenComplete in interface Promise<T>
      Parameters:
      fn - a consumer that consumes a result and an exception of this promise
    • whenComplete

      public Promise<T> whenComplete(io.activej.common.function.ConsumerEx<? super T> fn, io.activej.common.function.ConsumerEx<Exception> exceptionFn)
      Description copied from interface: Promise
      Subscribes given consumers to be executed after this Promise completes (either successfully or exceptionally). The first consumer will be executed if this Promise completes successfully, otherwise the second promise will be executed. Returns a new Promise.

      Each consumer may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenComplete in interface Promise<T>
      Parameters:
      fn - consumer that consumes a result of this promise
      exceptionFn - consumer that consumes an exception of this promise
    • whenComplete

      public Promise<T> whenComplete(io.activej.common.function.RunnableEx action)
      Description copied from interface: Promise
      Subscribes given runnable to be executed after this Promise completes (either successfully or exceptionally). Returns a new Promise.

      A runnable may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenComplete in interface Promise<T>
      Parameters:
      action - runnable to be executed after this promise completes
    • whenResult

      public Promise<T> whenResult(io.activej.common.function.ConsumerEx<? super T> fn)
      Description copied from interface: Promise
      Subscribes given consumer to be executed after this Promise completes successfully. Returns a new Promise.

      A consumer may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenResult in interface Promise<T>
      Parameters:
      fn - consumer that consumes a result of this promise
    • whenResult

      public Promise<T> whenResult(io.activej.common.function.RunnableEx action)
      Description copied from interface: Promise
      Subscribes given runnable to be executed after this Promise completes successfully and a result of this Promise satisfy a given Predicate. Returns a new Promise.

      A runnable may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenResult in interface Promise<T>
      Parameters:
      action - runnable to be executed after this promise completes successfully
    • whenException

      public Promise<T> whenException(io.activej.common.function.ConsumerEx<Exception> fn)
      Description copied from interface: Promise
      Subscribes given consumer to be executed after this Promise completes exceptionally. Returns a new Promise.

      A consumer may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenException in interface Promise<T>
      Parameters:
      fn - consumer that consumes an exception of this promise
    • whenException

      public <E extends Exception> Promise<T> whenException(Class<E> clazz, io.activej.common.function.ConsumerEx<? super E> fn)
      Description copied from interface: Promise
      Subscribes given consumer to be executed after this Promise completes exceptionally and an exception of this Promise is an instance of a given exception Class. Returns a new Promise.

      A consumer may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenException in interface Promise<T>
      Parameters:
      clazz - an exception class that exception is tested against. A consumer is called only if an exception of this promise is an instance of the specified class
      fn - consumer that consumes an exception of this promise
    • whenException

      public Promise<T> whenException(io.activej.common.function.RunnableEx action)
      Description copied from interface: Promise
      Subscribes given runnable to be executed after this Promise completes exceptionally. Returns a new Promise.

      A runnable may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenException in interface Promise<T>
      Parameters:
      action - runnable to be executed after this promise completes exceptionally
    • whenException

      public Promise<T> whenException(Class<? extends Exception> clazz, io.activej.common.function.RunnableEx action)
      Description copied from interface: Promise
      Subscribes given runnable to be executed after this Promise completes exceptionally and an exception of this Promise is an instance of a given exception Class. Returns a new Promise.

      A runnable may throw a checked exception. In this case the resulting promise is completed exceptionally with a thrown exception.

      Specified by:
      whenException in interface Promise<T>
      Parameters:
      clazz - an exception class that exception is tested against. A consumer is called only if an exception of this promise is an instance of the specified class
      action - runnable to be executed after this promise completes exceptionally and an exception of this Promise is an instance of a given exception Class.
    • combine

      public <U, V> Promise<V> combine(Promise<? extends U> other, io.activej.common.function.BiFunctionEx<? super T,? super U,? extends V> fn)
      Description copied from interface: Promise
      Returns a new Promise that, when this and the other given Promise both complete, is executed with the two results as arguments to the supplied function.
      Specified by:
      combine in interface Promise<T>
      Parameters:
      other - the other Promise
      fn - the function to use to compute the value of the returned Promise
      Returns:
      new Promise
    • both

      public Promise<Void> both(Promise<?> other)
      Description copied from interface: Promise
      Returns a new Promise when both this and provided other Promises complete.
      Specified by:
      both in interface Promise<T>
      Parameters:
      other - the other Promise
      Returns:
      Promise of null when both this and other Promise complete
    • either

      public Promise<T> either(Promise<? extends T> other)
      Description copied from interface: Promise
      Returns the Promise which was completed first.
      Specified by:
      either in interface Promise<T>
      Parameters:
      other - the other Promise
      Returns:
      the first completed Promise
    • async

      public Promise<T> async()
      Description copied from interface: Promise
      Ensures that Promise completes asynchronously: if this Promise is already completed, its completion will be posted to the next reactor tick. Otherwise, does nothing.
      Specified by:
      async in interface Promise<T>
    • toTry

      public Promise<io.activej.common.collection.Try<T>> toTry()
      Description copied from interface: Promise
      Returns Promise that always completes successfully with result or exception wrapped in Try.
      Specified by:
      toTry in interface Promise<T>
    • toVoid

      public Promise<Void> toVoid()
      Description copied from interface: Promise
      Waits for result and discards it.
      Specified by:
      toVoid in interface Promise<T>
    • next

      public void next(NextPromise<? super T,?> cb)
      Description copied from interface: Promise
      Calls a callback after this promise is completed, passing both a result and an exception of a promise to the callback. This method is similar to Promise.whenComplete(BiConsumerEx) but does not create or return a new promise. A Callback interface also prohibits throwing checked exceptions.

      In most cases Promise.whenComplete(BiConsumerEx) is preferred. Fall back to using this method only if you expect a performance hit from constantly calling Promise.whenComplete(BiConsumerEx) and creating new promises as a result.

      Specified by:
      next in interface Promise<T>
      Parameters:
      cb - a callback to be called once a promise completes
    • subscribe

      public Promise<T> subscribe(Callback<? super T> cb)
      Specified by:
      subscribe in interface Promise<T>
    • toCompletableFuture

      public CompletableFuture<T> toCompletableFuture()
      Description copied from interface: Promise
      Wraps Promise into CompletableFuture.
      Specified by:
      toCompletableFuture in interface Promise<T>