Package org.drasyl.util
Class FutureComposer<T>
java.lang.Object
org.drasyl.util.FutureComposer<T>
- Type Parameters:
T
- result type of the current step'sFuture
This utility class lat you chain up
Future
s.
A common need is to execute two or more asynchronous operations back to back, where each subsequent operation starts when the previous operation succeeds, with the result from the previous step.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <R> FutureComposer<R>
composeFailedFuture
(Throwable cause) static <R> FutureComposer<R>
composeFuture
(io.netty.util.concurrent.Future<R> future) static FutureComposer<Void>
static <R> FutureComposer<R>
composeSucceededFuture
(R result) io.netty.util.concurrent.Future<T>
finish
(io.netty.util.concurrent.EventExecutor executor) <R> FutureComposer<R>
then
(io.netty.util.concurrent.Future<R> future) Returns a newFutureComposer
that will complete if all previousFuture
s andfuture
have been completed.<R> FutureComposer<R>
then
(Function<io.netty.util.concurrent.Future<T>, FutureComposer<R>> mapper) Returns a newFutureComposer
that will complete if all previousFuture
s and theFutureComposer
returned bymapper
have been completed.<R> FutureComposer<R>
then
(Supplier<FutureComposer<R>> mapper)
-
Method Details
-
finish
Binds allFuture
s in thisFutureComposer
toexecutor
. ReturnsFuture
that completes if all previousFuture
s in thisFutureComposer
have been completed.- Parameters:
executor
-EventExecutor
to bind allFuture
s in thisFutureComposer
to- Returns:
Future
that completes if all previousFuture
s in thisFutureComposer
have been completed
-
then
Returns a newFutureComposer
that will complete if all previousFuture
s andfuture
have been completed. -
then
public <R> FutureComposer<R> then(Function<io.netty.util.concurrent.Future<T>, FutureComposer<R>> mapper) Returns a newFutureComposer
that will complete if all previousFuture
s and theFutureComposer
returned bymapper
have been completed.Future
will be passed tomapper
. -
then
-
composeFuture
- Type Parameters:
R
- type offuture
- Parameters:
future
- the initialFuture
- Returns:
- new
FutureComposer
whose firstFuture
isfuture
-
composeSucceededFuture
- Type Parameters:
R
- type ofresult
- Parameters:
result
- result of the initialFuture
- Returns:
- new
FutureComposer
whose firstFuture
was successfully completed withresult
-
composeSucceededFuture
- Returns:
- new
FutureComposer
whose firstFuture
was successfully completed withnull
-
composeFailedFuture
- Type Parameters:
R
- type ofFuture
- Parameters:
cause
- cause that failed theFuture
- Returns:
- new
FutureComposer
whose firstFuture
was failed withcause
-