Package com.thewinterframework.scheduler
Interface PluginScheduler
public interface PluginScheduler
Interface for scheduling tasks within a plugin environment.
-
Method Summary
Modifier and TypeMethodDescriptionvoidCancels all scheduled tasks.voidcancelTask(int taskId) Cancels a specific task by its ID.voidensureSync(Runnable runnable) Ensures a task runs synchronouslyGets the executor for running tasks on the main thread.<T> CompletableFuture<T> Gets a value ensuring the supplier is executed on the main threadintRuns a task asynchronously.intrunAtFixedRateAsync(Runnable runnable, long initialDelay, long intervalTicks, TimeUnit unit) Runs a task at a fixed rate asynchronously.intrunAtFixedRateSync(Runnable runnable, long initialDelay, long intervalTicks, TimeUnit unit) Runs a task at a fixed rate synchronously.intrunDelayedAsync(Runnable runnable, long delayTicks, TimeUnit unit) Runs a task after a delay asynchronously.intrunDelayedSync(Runnable runnable, long delayTicks, TimeUnit unit) Runs a task after a delay synchronously.intRuns a task synchronously.
-
Method Details
-
getMainThreadExecutor
Executor getMainThreadExecutor()Gets the executor for running tasks on the main thread.- Returns:
- the main thread executor
-
cancelAllTasks
void cancelAllTasks()Cancels all scheduled tasks. -
cancelTask
void cancelTask(int taskId) Cancels a specific task by its ID.- Parameters:
taskId- the ID of the task to cancel
-
runAsync
Runs a task asynchronously.- Parameters:
runnable- the task to run- Returns:
- the ID of the scheduled task
-
runSync
Runs a task synchronously.- Parameters:
runnable- the task to run- Returns:
- the ID of the scheduled task
-
runAtFixedRateAsync
Runs a task at a fixed rate asynchronously.- Parameters:
runnable- the task to runinitialDelay- the delay before the first executionintervalTicks- the interval between executionsunit- the time unit of the interval- Returns:
- the ID of the scheduled task
-
runAtFixedRateSync
Runs a task at a fixed rate synchronously.- Parameters:
runnable- the task to runinitialDelay- the delay before the first executionintervalTicks- the interval between executionsunit- the time unit of the interval- Returns:
- the ID of the scheduled task
-
runDelayedAsync
Runs a task after a delay asynchronously.- Parameters:
runnable- the task to rundelayTicks- the delay before execution in ticksunit- the time unit of the delay- Returns:
- the ID of the scheduled task
-
runDelayedSync
Runs a task after a delay synchronously.- Parameters:
runnable- the task to rundelayTicks- the delay before execution in ticksunit- the time unit of the delay- Returns:
- the ID of the scheduled task
-
ensureSync
Ensures a task runs synchronously- Parameters:
runnable- the task to run
-
getSync
Gets a value ensuring the supplier is executed on the main thread- Type Parameters:
T- the type of the value- Parameters:
supplier- the supplier to get the value from- Returns:
- a CompletableFuture that will complete with the value
-