Package io.activej.promise
Class NextPromise<T,R>
- java.lang.Object
-
- io.activej.promise.NextPromise<T,R>
-
- All Implemented Interfaces:
AsyncComputation<R>,Callback<T>,Promisable<R>,Promise<R>
public abstract class NextPromise<T,R> extends Object
Helps to create sequent chains ofPromises.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.activej.promise.Promise
Promise.BlockingCallable<V>, Promise.BlockingRunnable
-
-
Constructor Summary
Constructors Constructor Description NextPromise()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Promise<T>async()Ensures thatPromisecompletes asynchronously: if thisPromiseis already completed, its completion will be posted to next eventloop tick.@NotNull Promise<Void>both(@NotNull Promise<?> other)Returns a newPromisewhen both this and providedotherPromisescomplete.<U,V>
@NotNull Promise<V>combine(@NotNull Promise<? extends U> other, @NotNull BiFunction<? super T,? super U,? extends V> fn)Returns a newPromisethat, when this and the other givenPromiseboth complete, is executed with the two results as arguments to the supplied function.protected voidcomplete(T value)protected voidcomplete(T value, @Nullable Throwable e)protected voidcompleteExceptionally(@Nullable Throwable e)protected Stringdescribe()@NotNull Promise<T>either(@NotNull Promise<? extends T> other)Returns thePromisewhich was completed first.ThrowablegetException()TgetResult()io.activej.common.collection.Try<T>getTry()booleanisComplete()booleanisException()booleanisResult()<U> @NotNull Promise<U>map(@NotNull Function<? super T,? extends U> fn)Returns a newPromisewhich is executed with thisPromise's result as the argument to the provided function when thisPromisecompletes successfully.<U> @NotNull Promise<U>mapEx(@NotNull BiFunction<? super T,Throwable,? extends U> fn)Returns a newPromisewhich is executed with thisPromise's result as the argument to the provided function when thisPromisecompletes either successfully (whenexceptionisnull) or with an exception.<U,P extends Callback<? super T> & Promise<U>>
@NotNull Promise<U>next(P promise)Executes givenpromiseafter execution of thisPromisecompletes.protected static @Nullable VoidrecycleToVoid(Object item)voidreset()voidresetCallbacks()protected voidsubscribe(@NotNull Callback<? super T> callback)<U> @NotNull Promise<U>then(@NotNull Function<? super T,? extends Promise<? extends U>> fn)Returns a newPromisewhich, when thisPromisecompletes successfully, is executed with thisPromise'sresult as the argument to the supplied function.<U> @NotNull Promise<U>then(@NotNull Supplier<? extends Promise<? extends U>> fn)<U> @NotNull Promise<U>thenEx(@NotNull BiFunction<? super T,Throwable,? extends Promise<? extends U>> fn)Returns a newPromisewhich, when thisPromisecompletes either successfully (if exception isnull) or exceptionally (if exception is notnull), is executed with thisPromise'sresult as the argument to the supplied function.@NotNull CompletableFuture<T>toCompletableFuture()WrapsPromiseintoCompletableFuture.StringtoString()@NotNull Promise<io.activej.common.collection.Try<T>>toTry()ReturnsPromisethat always completes successfully with result or exception wrapped inTry.@NotNull Promise<Void>toVoid()Waits for result and discards it.protected booleantryComplete(T value)protected booleantryComplete(T value, @Nullable Throwable e)protected booleantryCompleteExceptionally(@NotNull Throwable e)@NotNull Promise<T>whenComplete(@NotNull Callback<? super T> action)Subscribes given action to be executed after thisPromisecompletes and returns a newPromise.@NotNull Promise<T>whenComplete(@NotNull Runnable action)Subscribes given action to be executed after thisPromisecompletes and returns a newPromise.Promise<T>whenException(@NotNull Runnable action)Promise<T>whenException(@NotNull Consumer<Throwable> action)Subscribes given action to be executed after thisPromisecompletes exceptionally and returns a newPromise.Promise<T>whenResult(@NotNull Runnable action)@NotNull Promise<T>whenResult(Consumer<? super T> action)Subscribes given action to be executed after thisPromisecompletes successfully and returns a newPromise.
-
-
-
Method Detail
-
reset
public void reset()
-
resetCallbacks
public void resetCallbacks()
-
isComplete
public final boolean isComplete()
- Specified by:
isCompletein interfacePromise<T>
-
isException
public final boolean isException()
- Specified by:
isExceptionin interfacePromise<T>
-
getException
public Throwable getException()
- Specified by:
getExceptionin interfacePromise<T>
-
getTry
public io.activej.common.collection.Try<T> getTry()
-
complete
protected void complete(@Nullable T value, @Nullable @Nullable Throwable e)
-
complete
protected void complete(@Nullable T value)
-
completeExceptionally
protected void completeExceptionally(@Nullable @Nullable Throwable e)
-
tryComplete
protected boolean tryComplete(@Nullable T value, @Nullable @Nullable Throwable e)
-
tryComplete
protected boolean tryComplete(@Nullable T value)
-
tryCompleteExceptionally
protected boolean tryCompleteExceptionally(@NotNull @NotNull Throwable e)
-
next
@NotNull public <U,P extends Callback<? super T> & Promise<U>> @NotNull Promise<U> next(@NotNull P promise)
Description copied from interface:PromiseExecutes givenpromiseafter execution of thisPromisecompletes.
-
subscribe
protected void subscribe(@NotNull @NotNull Callback<? super T> callback)
-
map
@NotNull public <U> @NotNull Promise<U> map(@NotNull @NotNull Function<? super T,? extends U> fn)
Description copied from interface:PromiseReturns a newPromisewhich is executed with thisPromise's result as the argument to the provided function when thisPromisecompletes successfully.- Specified by:
mapin interfacePromise<T>- Parameters:
fn- function to be applied to thisPromisewhen it completes successfully- Returns:
- new
Promisewhich is the result of function applied to the result of thisPromise - See Also:
CompletionStage.thenApply(Function)
-
mapEx
@NotNull public <U> @NotNull Promise<U> mapEx(@NotNull @NotNull BiFunction<? super T,Throwable,? extends U> fn)
Description copied from interface:PromiseReturns a newPromisewhich is executed with thisPromise's result as the argument to the provided function when thisPromisecompletes either successfully (whenexceptionisnull) or with an exception.
-
then
@NotNull public <U> @NotNull Promise<U> then(@NotNull @NotNull Function<? super T,? extends Promise<? extends U>> fn)
Description copied from interface:PromiseReturns a newPromisewhich, when thisPromisecompletes successfully, is executed with thisPromise'sresult as the argument to the supplied function.
-
then
@NotNull public <U> @NotNull Promise<U> then(@NotNull @NotNull Supplier<? extends Promise<? extends U>> fn)
-
thenEx
@NotNull public <U> @NotNull Promise<U> thenEx(@NotNull @NotNull BiFunction<? super T,Throwable,? extends Promise<? extends U>> fn)
Description copied from interface:PromiseReturns a newPromisewhich, when thisPromisecompletes either successfully (if exception isnull) or exceptionally (if exception is notnull), is executed with thisPromise'sresult as the argument to the supplied function.
-
whenComplete
@NotNull public @NotNull Promise<T> whenComplete(@NotNull @NotNull Callback<? super T> action)
Description copied from interface:PromiseSubscribes given action to be executed after thisPromisecompletes and returns a newPromise.- Specified by:
whenCompletein interfacePromise<T>- Parameters:
action- to be executed
-
whenComplete
@NotNull public @NotNull Promise<T> whenComplete(@NotNull @NotNull Runnable action)
Description copied from interface:PromiseSubscribes given action to be executed after thisPromisecompletes and returns a newPromise.- Specified by:
whenCompletein interfacePromise<T>- Parameters:
action- to be executed
-
whenResult
@NotNull public @NotNull Promise<T> whenResult(Consumer<? super T> action)
Description copied from interface:PromiseSubscribes given action to be executed after thisPromisecompletes successfully and returns a newPromise.- Specified by:
whenResultin interfacePromise<T>- Parameters:
action- to be executed
-
whenResult
public Promise<T> whenResult(@NotNull @NotNull Runnable action)
- Specified by:
whenResultin interfacePromise<T>
-
whenException
public Promise<T> whenException(@NotNull @NotNull Consumer<Throwable> action)
Description copied from interface:PromiseSubscribes given action to be executed after thisPromisecompletes exceptionally and returns a newPromise.- Specified by:
whenExceptionin interfacePromise<T>- Parameters:
action- to be executed
-
whenException
public Promise<T> whenException(@NotNull @NotNull Runnable action)
- Specified by:
whenExceptionin interfacePromise<T>
-
async
@NotNull public @NotNull Promise<T> async()
Description copied from interface:PromiseEnsures thatPromisecompletes asynchronously: if thisPromiseis already completed, its completion will be posted to next eventloop tick. Otherwise, does nothing.
-
combine
@NotNull public <U,V> @NotNull Promise<V> combine(@NotNull @NotNull Promise<? extends U> other, @NotNull @NotNull BiFunction<? super T,? super U,? extends V> fn)
Description copied from interface:PromiseReturns a newPromisethat, when this and the other givenPromiseboth complete, is executed with the two results as arguments to the supplied function.
-
both
@NotNull public @NotNull Promise<Void> both(@NotNull @NotNull Promise<?> other)
Description copied from interface:PromiseReturns a newPromisewhen both this and providedotherPromisescomplete.
-
either
@NotNull public @NotNull Promise<T> either(@NotNull @NotNull Promise<? extends T> other)
Description copied from interface:PromiseReturns thePromisewhich was completed first.
-
toTry
@NotNull public @NotNull Promise<io.activej.common.collection.Try<T>> toTry()
Description copied from interface:PromiseReturnsPromisethat always completes successfully with result or exception wrapped inTry.
-
toVoid
@NotNull public @NotNull Promise<Void> toVoid()
Description copied from interface:PromiseWaits for result and discards it.
-
toCompletableFuture
@NotNull public @NotNull CompletableFuture<T> toCompletableFuture()
Description copied from interface:PromiseWrapsPromiseintoCompletableFuture.- Specified by:
toCompletableFuturein interfacePromise<T>
-
describe
protected String describe()
-
-