Class DurableFuture<T>
- Type Parameters:
T- type of the future result
- Direct Known Subclasses:
Awakeable,CallDurableFuture,Select
DurableFuture allows to await an asynchronous result. Once await() is called,
the execution stops until the asynchronous result is available.
The result can be either a success or a failure. In case of a failure, await() will
throw a TerminalException.
NOTE: This interface MUST NOT be accessed concurrently since it can lead to different orderings of user actions, corrupting the execution of the invocation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DurableFuture<Void> all(DurableFuture<?> first, DurableFuture<?> second, DurableFuture<?>... others) Create anDurableFuturethat awaits all the given futures.static DurableFuture<Void> all(List<DurableFuture<?>> durableFutures) Create anDurableFuturethat awaits all the given futures.static DurableFuture<Integer> any(DurableFuture<?> first, DurableFuture<?> second, DurableFuture<?>... others) Create anDurableFuturethat awaits any of the given futures.static DurableFuture<Integer> any(List<DurableFuture<?>> durableFutures) Create anDurableFuturethat awaits any of the given futures.protected abstract AsyncResult<T> final Tawait()Wait for thisDurableFutureto complete.final TSame asawait(), but throws aTimeoutExceptionif thisDurableFuturedoesn't complete before the providedtimeout.final <U> DurableFuture<U> map(ThrowingFunction<T, U> mapper) Map the success result of thisDurableFuture.final <U> DurableFuture<U> map(ThrowingFunction<T, U> successMapper, ThrowingFunction<TerminalException, U> failureMapper) Map both the success and the failure result of thisDurableFuture.final DurableFuture<T> mapFailure(ThrowingFunction<TerminalException, T> failureMapper) Map the failure result of thisDurableFuture.protected abstract Executorfinal DurableFuture<T> withTimeout(Duration timeout)
-
Constructor Details
-
DurableFuture
public DurableFuture()
-
-
Method Details
-
asyncResult
-
serviceExecutor
-
await
Wait for thisDurableFutureto complete.Executing this method may trigger the suspension of the function.
NOTE: You should never wrap this function in a try-catch catching
Throwable, as it will catchAbortedExecutionExceptionas well, which will prevent the service invocation to orderly suspend.- Throws:
TerminalException- if this future was completed with a failure
-
await
Same asawait(), but throws aTimeoutExceptionif thisDurableFuturedoesn't complete before the providedtimeout.- Throws:
TerminalException
-
withTimeout
- Returns:
- a
DurableFuturethat throws aTimeoutExceptionif this future doesn't complete before the providedtimeout.
-
map
Map the success result of thisDurableFuture.- Parameters:
mapper- the mapper to execute if thisDurableFuturecompletes with success. The mapper can throw aTerminalException, thus failing the resultingDurableFuture.- Returns:
- a new
DurableFuturewith the mapped result, when completed
-
map
public final <U> DurableFuture<U> map(ThrowingFunction<T, U> successMapper, ThrowingFunction<TerminalException, U> failureMapper) Map both the success and the failure result of thisDurableFuture.- Parameters:
successMapper- the mapper to execute if thisDurableFuturecompletes with success. The mapper can throw aTerminalException, thus failing the resultingDurableFuture.failureMapper- the mapper to execute if thisDurableFuturecompletes with failure. The mapper can throw aTerminalException, thus failing the resultingDurableFuture.- Returns:
- a new
DurableFuturewith the mapped result, when completed
-
mapFailure
Map the failure result of thisDurableFuture.- Parameters:
failureMapper- the mapper to execute if thisDurableFuturecompletes with failure. The mapper can throw aTerminalException, thus failing the resultingDurableFuture.- Returns:
- a new
DurableFuturewith the mapped result, when completed
-
any
public static DurableFuture<Integer> any(DurableFuture<?> first, DurableFuture<?> second, DurableFuture<?>... others) Create anDurableFuturethat awaits any of the given futures. The resultingDurableFuturereturns the index of the completed future in the provided list.- See Also:
-
any
Create anDurableFuturethat awaits any of the given futures. The resultingDurableFuturereturns the index of the completed future in the provided list.An empty list is not supported and will throw
IllegalArgumentException.- See Also:
-
all
public static DurableFuture<Void> all(DurableFuture<?> first, DurableFuture<?> second, DurableFuture<?>... others) Create anDurableFuturethat awaits all the given futures.The behavior is the same as
CompletableFuture.allOf(CompletableFuture[]). -
all
Create anDurableFuturethat awaits all the given futures.An empty list is not supported and will throw
IllegalArgumentException.The behavior is the same as
CompletableFuture.allOf(CompletableFuture[]).
-