Interface TaskHandle
- All Known Implementing Classes:
TaskRecord
-
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Prevents every run that has not started.Completes when the task will never run again: normally after a successful one-shot; exceptionally with its thrown exception forTaskState.FAILED,CancellationExceptionforTaskState.CANCELLED(including owner unload), orTaskRetiredExceptionforTaskState.RETIRED.booleanReturns whether this task was submitted withTaskContext.runRepeating(Duration, Duration, Consumer).state()Returns the current lifecycle state.
-
Method Details
-
state
TaskState state()Returns the current lifecycle state. -
isRepeating
boolean isRepeating()Returns whether this task was submitted withTaskContext.runRepeating(Duration, Duration, Consumer). -
cancel
boolean cancel()Prevents every run that has not started. Never interrupts a run in progress. Idempotent.A one-shot task that is already
TaskState.RUNNINGcannot be cancelled: this returnsfalseand the task still endsTaskState.COMPLETEDorTaskState.FAILED(as Paper'sScheduledTask#cancel()reportsRUNNING). For a repeating task whose run is in progress this returnstrue, the state becomesTaskState.CANCELLEDat once andcompletion()completes with aCancellationException; the current run finishes, and an exception it throws is logged with the owner's name like any other repeating failure.- Returns:
trueonly for the call that moved the task toTaskState.CANCELLED
-
completion
CompletionStage<Void> completion()Completes when the task will never run again: normally after a successful one-shot; exceptionally with its thrown exception forTaskState.FAILED,CancellationExceptionforTaskState.CANCELLED(including owner unload), orTaskRetiredExceptionforTaskState.RETIRED.A one-shot body failure from
TaskContext.run(Runnable),TaskContext.runLater(java.time.Duration, Runnable)orTaskContext.execute(Runnable)is also logged exactly once at WARNING with its owner's name and original throwable. ATaskContext.supply(java.util.function.Supplier)failure is reported only through its future unless that future was cancelled after the body started.This is a minimal stage: callers cannot complete or cancel the task through it. Non-async dependent actions run on the thread completing the stage.
-