Package de.linusdev.lutils.async
Class AbstractFuture<R,S,T extends Task<R,S>>
java.lang.Object
de.linusdev.lutils.async.AbstractFuture<R,S,T>
- All Implemented Interfaces:
Future<R,,S> HasAsyncManager
- Direct Known Subclasses:
CompletableFuture,ExecutableFuture
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull AsyncManagerprotected booleanprotected booleanprotected final Objectprotected @Nullable ComputationResult<R,S> protected booleanprotected final Tprotected @Nullable ResultConsumer<R,S> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFuture(T task, @NotNull AsyncManager asyncManager) -
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.@NotNull AsyncManagerprotected TgetTask()booleanbooleanbooleanisDone()then(@NotNull ResultConsumer<R, S> consumer) Given consumer will be called afterFuture's execution has finished and result or error is ready.
-
Field Details
-
asyncManager
-
task
-
canceled
protected volatile boolean canceled -
started
protected volatile boolean started -
done
protected volatile boolean done -
lock
-
before
-
then
-
result
-
-
Constructor Details
-
AbstractFuture
-
-
Method Details
-
getTask
-
cancel
Description copied from interface:FutureCancels this future, if it is not already executing. -
isCanceled
public boolean isCanceled()- Specified by:
isCanceledin interfaceFuture<R,S> - Returns:
trueif thisFutureis canceled.
-
hasStarted
public boolean hasStarted()- Specified by:
hasStartedin interfaceFuture<R,S> - Returns:
trueif thisFuturehas started its execution.
-
isDone
public boolean isDone() -
beforeExecution
@NotNull public @NotNull Future<R,S> beforeExecution(@NotNull @NotNull Consumer<Future<R, S>> consumer) Description copied from interface:Future -
then
Description copied from interface:FutureGiven consumer will be called afterFuture's execution has finished and result or error is ready. -
get
Description copied from interface:FutureWaits the current Thread until thisFuturehas been executed. If execution has already finished, this method will return immediately.- Specified by:
getin interfaceFuture<R,S> - Returns:
ComputationResultcontaining the result, secondary result and a potential error.- Throws:
InterruptedException- if interrupted while waiting
-
getAsyncManager
- Specified by:
getAsyncManagerin interfaceHasAsyncManager
-