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
Futures.
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 newFutureComposerthat will complete if all previousFutures andfuturehave been completed.<R> FutureComposer<R>then(Function<io.netty.util.concurrent.Future<T>, FutureComposer<R>> mapper) Returns a newFutureComposerthat will complete if all previousFutures and theFutureComposerreturned bymapperhave been completed.<R> FutureComposer<R>then(Supplier<FutureComposer<R>> mapper)
-
Method Details
-
finish
Binds allFutures in thisFutureComposertoexecutor. ReturnsFuturethat completes if all previousFutures in thisFutureComposerhave been completed.- Parameters:
executor-EventExecutorto bind allFutures in thisFutureComposerto- Returns:
Futurethat completes if all previousFutures in thisFutureComposerhave been completed
-
then
Returns a newFutureComposerthat will complete if all previousFutures andfuturehave been completed. -
then
public <R> FutureComposer<R> then(Function<io.netty.util.concurrent.Future<T>, FutureComposer<R>> mapper) Returns a newFutureComposerthat will complete if all previousFutures and theFutureComposerreturned bymapperhave been completed.Futurewill be passed tomapper. -
then
-
composeFuture
- Type Parameters:
R- type offuture- Parameters:
future- the initialFuture- Returns:
- new
FutureComposerwhose firstFutureisfuture
-
composeSucceededFuture
- Type Parameters:
R- type ofresult- Parameters:
result- result of the initialFuture- Returns:
- new
FutureComposerwhose firstFuturewas successfully completed withresult
-
composeSucceededFuture
- Returns:
- new
FutureComposerwhose firstFuturewas successfully completed withnull
-
composeFailedFuture
- Type Parameters:
R- type ofFuture- Parameters:
cause- cause that failed theFuture- Returns:
- new
FutureComposerwhose firstFuturewas failed withcause
-