Package de.linusdev.lutils.async
Interface Future<R,S>
- Type Parameters:
R- the result typeS- the secondary result type. usually contains information about the task's execution process.
- All Superinterfaces:
HasAsyncManager
- All Known Implementing Classes:
AbstractFuture,CompletableFuture,ConditionedFuture,ExecutableFuture,QueueableFuture
A
Before the
Once the future has finished (if it wasn't canceled):
Meaning that the
If the future was
If any then listener (
Future represents a Task that will be executed in the future and whose result or error will
be retrieved.
Before the
Task bound to this future will supposedly start execution:
before execution listener will be called before and can still cancel() this future.
Once the future has finished (if it wasn't canceled):
Meaning that the
Task has finished execution . The following actions will follow
in the following order
-
all Threads waiting on
get()will be notified -
All result listeners (
see,see,see) will be called in the order they have been added to thisFuture.
If the future was
canceled:
-
All Threads waiting on
get()will be resumed and aCancellationExceptionwill be thrown. -
The
Taskwill not be executed. -
beforeExecution(Consumer)listener will not be called.
If any then listener (
see, see, see)
is set after the result has already been retrieved:
The listener will be called immediately in the setting thread
-
Method Summary
Modifier and TypeMethodDescriptionbeforeExecution(@NotNull Consumer<Future<R, S>> consumer) Given consumer will be called before theFuturewill be executed.cancel()Cancels this future, if it is not already executing.@NotNull ComputationResult<R,S> get()Waits the current Thread until thisFuturehas been executed.default RWaits the current Thread until thisFuturehas been executed.booleanbooleanbooleanisDone()then(@NotNull ResultAndErrorConsumer<R, S> consumer) Given consumer will be called afterFuture's execution has finished and result or error is ready.then(@NotNull ResultConsumer<R, S> consumer) Given consumer will be called afterFuture's execution has finished and result or error is ready.then(@NotNull SingleResultConsumer<R, S> consumer) Given consumer will be called afterFuture's execution has finished and result or error is ready.Methods inherited from interface de.linusdev.lutils.async.manager.HasAsyncManager
getAsyncManager
-
Method Details
-
cancel
Cancels this future, if it is not already executing.- Returns:
- the canceled
Future
-
isCanceled
boolean isCanceled()- Returns:
trueif thisFutureis canceled.
-
hasStarted
boolean hasStarted()- Returns:
trueif thisFuturehas started its execution.
-
isDone
boolean isDone()- Returns:
trueif thisFutureis done (execution finished and result or error is ready).
-
beforeExecution
-
then
Given consumer will be called afterFuture's execution has finished and result or error is ready.- Parameters:
consumer-ResultConsumer- Returns:
- the
Futureitself.
-
then
Given consumer will be called afterFuture's execution has finished and result or error is ready.- Parameters:
consumer-ResultAndErrorConsumer- Returns:
- the
Futureitself.
-
then
Given consumer will be called afterFuture's execution has finished and result or error is ready.- Parameters:
consumer-SingleResultConsumer- Returns:
- the
Futureitself.
-
get
@Blocking @NotNull @NotNull ComputationResult<R,S> get() throws InterruptedException, CancellationExceptionWaits the current Thread until thisFuturehas been executed. If execution has already finished, this method will return immediately.- Returns:
ComputationResultcontaining the result, secondary result and a potential error.- Throws:
InterruptedException- if interrupted while waitingCancellationException- if theFuturehas been canceled.
-
getResult
Waits the current Thread until thisFuturehas been executed. If execution has already finished, this method will return immediately.- Returns:
Futureresult- Throws:
InterruptedException- if interrupted while waitingErrorException- if theFuturereturned with an error.
-