Class ProgressiveTask<T>
java.lang.Object
io.github.thecsdev.tcdcommons.api.util.thread.ProgressiveTask<T>
- Type Parameters:
T
- The type of the result that is produced by thisProgressiveTask
.
- Direct Known Subclasses:
DescriptiveProgressiveTask
Represents a task that is happening or developing gradually or in stages.
The task is executed asynchronously, and its progress is tracked.
The task is executed asynchronously, and its progress is tracked.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
-
Field Summary
Modifier and TypeFieldDescriptionfinal TEvent
<ProgressiveTask.PtFinished> final TEvent
<ProgressiveTask.PtPc> ATEvent
that is invoked whensetProgress(float)
is called. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Clears all flags associated with thisProgressiveTask
, making it look as if it were never executed before.final void
Synchronously executes thisProgressiveTask
.final @Nullable Throwable
getError()
If the task execution fails due a raisedThrowable
, there will be nogetResult()
, and instead, there will be aThrowable
returned bygetError()
.final float
Retrieves the current progress of thisProgressiveTask
's execution.final T
Returns the result of thisProgressiveTask
.final boolean
Returnstrue
if thisProgressiveTask
has finished executing.final boolean
Returnstrue
if thisProgressiveTask
is currently executing.protected abstract T
The main logic responsible for executing thisProgressiveTask
.
This is where the task's main code goes.protected final void
setProgress
(float progress) Sets thisProgressiveTask
's current "progress" value.
-
Field Details
-
eProgressChanged
ATEvent
that is invoked whensetProgress(float)
is called. -
eFinished
-
-
Constructor Details
-
ProgressiveTask
public ProgressiveTask()
-
-
Method Details
-
getProgress
public final float getProgress()Retrieves the current progress of thisProgressiveTask
's execution.- See Also:
-
setProgress
protected final void setProgress(float progress) Sets thisProgressiveTask
's current "progress" value. Used byonExecuteTask()
to indicate the current execution progress.- Parameters:
progress
- The 0-1 value indicating this task's current execution progress.
-
isRunning
public final boolean isRunning()Returnstrue
if thisProgressiveTask
is currently executing. -
isFinished
public final boolean isFinished()Returnstrue
if thisProgressiveTask
has finished executing. -
getResult
Returns the result of thisProgressiveTask
.- See Also:
-
getError
If the task execution fails due a raisedThrowable
, there will be nogetResult()
, and instead, there will be aThrowable
returned bygetError()
.- See Also:
-
clearFlags
Clears all flags associated with thisProgressiveTask
, making it look as if it were never executed before.- Throws:
IllegalStateException
- If the task is currently running.- See Also:
-
executeSync
public final void executeSync()Synchronously executes thisProgressiveTask
. -
onExecuteTask
The main logic responsible for executing thisProgressiveTask
.
This is where the task's main code goes.- Returns:
- The result of this
ProgressiveTask
that is then obtained viagetResult()
. - Throws:
Exception
-