public interface Stage<T>
SettableStage| Modifier and Type | Interface and Description |
|---|---|
static interface |
Stage.ThrowingFunction<T,R> |
| Modifier and Type | Field and Description |
|---|---|
static AsyncTimeoutException |
TIMEOUT_EXCEPTION |
| Modifier and Type | Method and Description |
|---|---|
Stage<Void> |
both(Stage<?> other)
Combines two
Stage in one and completes when both have been completed. |
<U,V> Stage<V> |
combine(Stage<? extends U> other,
BiFunction<? super T,? super U,? extends V> fn)
Combines two
Stage in one using fn. |
Stage<T> |
either(Stage<? extends T> other)
Combines two
Stage in one. |
static <T> Stage<T> |
of(T value)
Creates successfully completed
Stage |
static <T> Stage<T> |
of(T value,
Throwable throwable)
Creates a completed stage from value and throwable variables.
|
static <T> Stage<T> |
ofCallable(Executor executor,
Callable<? extends T> callable)
Runs some task in other thread (executed by a given
Executor) and returns a Stage for it. |
static <T> Stage<T> |
ofCallback(Consumer<SettableStage<T>> callbackConsumer) |
static <T> Stage<T> |
ofCompletionStage(CompletionStage<? extends T> completionStage)
Wraps Java
CompletionStage in a Stage, running it in current eventloop. |
static <T> Stage<T> |
ofException(Throwable throwable)
Creates exceptionally completed
Stage |
static <T> Stage<T> |
ofFuture(CompletableFuture<? extends T> future)
Creates a
Stage wrapper around default java CompletableFuture and runs it immediately. |
static <T> Stage<T> |
ofFuture(Executor executor,
Future<? extends T> future)
Wraps Java
Future in a Stage running it with given executor. |
static Stage<Void> |
ofRunnable(Executor executor,
Runnable runnable)
Adapter for
ofThrowingRunnable(Executor, ThrowingRunnable) |
static Stage<Void> |
ofThrowingRunnable(Executor executor,
ThrowingRunnable runnable)
Same as
ofCallable(Executor, Callable), but without a result (returned stage is only a marker of completion). |
Stage<T> |
post()
When this stage is completed it's completion will be postponed to the next eventloop tick.
|
Stage<T> |
postTo(Eventloop eventloop) |
<U,S extends BiConsumer<? super T,Throwable> & Stage<U>> |
then(S stage)
Executes given stage after execution of this stage completes
|
<U> Stage<U> |
thenApply(Function<? super T,? extends U> fn)
Applies fn to the result of this
Stage |
<U> Stage<U> |
thenApplyEx(BiFunction<? super T,Throwable,? extends U> fn)
Applies fn to the result or exception of this
Stage |
default <U> Stage<U> |
thenCallback(BiConsumer<? super T,SettableStage<U>> fn) |
<U> Stage<U> |
thenCompose(Function<? super T,? extends Stage<U>> fn)
Applies function to the result of this stage if it completes successfully.
|
<U> Stage<U> |
thenComposeEx(BiFunction<? super T,Throwable,? extends Stage<U>> fn)
Applies function to the result of this stage.
|
Stage<T> |
thenException(Function<? super T,Throwable> fn) |
Stage<T> |
thenRun(Runnable action)
Runs action after successful completion of this stage
|
Stage<T> |
thenRunEx(Runnable action)
Runs action after completion of this stage
|
default <U> Stage<U> |
thenTry(Stage.ThrowingFunction<? super T,? extends U> fn) |
Stage<T> |
timeout(Duration timeout)
Returns stage that completes successfully if this stage completes before timeout.
|
CompletableFuture<T> |
toCompletableFuture()
Wraps
Stage into CompletableFuture |
Stage<Try<T>> |
toTry()
Returns stage that always completes successfully with result or exception wrapped in Try
|
Stage<Void> |
toVoid()
Waits for result and discard it.
|
Stage<T> |
whenComplete(BiConsumer<? super T,Throwable> action)
Subscribes given action to be executed after this stage completes
|
Stage<T> |
whenException(Consumer<Throwable> action)
Subscribes given action to be executed after this stage completes exceptionally
|
Stage<T> |
whenResult(Consumer<? super T> action)
Subscribes given action to be executed after this stage completes successfully
|
static final AsyncTimeoutException TIMEOUT_EXCEPTION
static <T> Stage<T> of(@Nullable T value)
Stagevalue - result of Stagestatic <T> Stage<T> ofException(Throwable throwable)
Stagethrowable - Exceptionstatic <T> Stage<T> ofCallback(Consumer<SettableStage<T>> callbackConsumer)
static <T> Stage<T> of(@Nullable T value, @Nullable Throwable throwable)
thenComposeEx(BiFunction) passthroughs (eg. when mapping specific exceptions).value - value to wrap when exception is nullthrowable - possibly-null exception, determines type of stage completionstatic <T> Stage<T> ofFuture(CompletableFuture<? extends T> future)
Stage wrapper around default java CompletableFuture and runs it immediately.Stagestatic <T> Stage<T> ofCompletionStage(CompletionStage<? extends T> completionStage)
CompletionStage in a Stage, running it in current eventloop.completionStage - completion stage itselfStagestatic <T> Stage<T> ofFuture(Executor executor, Future<? extends T> future)
Future in a Stage running it with given executor.executor - executor to execute the future concurrentlyfuture - the future itselfStagestatic <T> Stage<T> ofCallable(Executor executor, Callable<? extends T> callable)
Executor) and returns a Stage for it.
Also manages external task count for current eventloop, so it wont shut down until the task is complete.executor - executor to execute the task concurrentlycallable - the task itselfStage for the given taskstatic Stage<Void> ofThrowingRunnable(Executor executor, ThrowingRunnable runnable)
ofCallable(Executor, Callable), but without a result (returned stage is only a marker of completion).static Stage<Void> ofRunnable(Executor executor, Runnable runnable)
ofThrowingRunnable(Executor, ThrowingRunnable)<U,S extends BiConsumer<? super T,Throwable> & Stage<U>> Stage<U> then(S stage)
U - type of resultstage - given stageStage<U> Stage<U> thenApply(Function<? super T,? extends U> fn)
Stagefn - function to applyStage that will apply given function<U> Stage<U> thenApplyEx(BiFunction<? super T,Throwable,? extends U> fn)
Stagefn - function to applyStage that will apply given functionStage<T> thenRun(Runnable action)
action - to be executedStage<T> thenRunEx(Runnable action)
action - to be executed<U> Stage<U> thenCompose(Function<? super T,? extends Stage<U>> fn)
fn - to be applied<U> Stage<U> thenComposeEx(BiFunction<? super T,Throwable,? extends Stage<U>> fn)
fn - to be applieddefault <U> Stage<U> thenCallback(BiConsumer<? super T,SettableStage<U>> fn)
Stage<T> whenComplete(BiConsumer<? super T,Throwable> action)
action - to be executedStageStage<T> whenResult(Consumer<? super T> action)
action - to be executedStageStage<T> whenException(Consumer<Throwable> action)
action - to be executedStagedefault <U> Stage<U> thenTry(Stage.ThrowingFunction<? super T,? extends U> fn)
<U,V> Stage<V> combine(Stage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
Stage in one using fn.other - Stage to combinefn - function to combine results of both stages into oneStage that completes when fn was applied on the result of both stagesStage<Void> both(Stage<?> other)
Stage in one and completes when both have been completed.other - Stage to combineStage<T> either(Stage<? extends T> other)
Stage in one.other - Stage to combineStageStage<Try<T>> toTry()
TryStage<T> timeout(@Nullable Duration timeout)
null is given, no timeout is applied.timeout - timeout in millisecondsStage<T> post()
CompletableFuture<T> toCompletableFuture()
Stage into CompletableFutureCopyright © 2019. All rights reserved.