Interface Scheduler

All Superinterfaces:
Executor
All Known Implementing Classes:
SchedulerManager

public sealed interface Scheduler extends Executor permits SchedulerManager (not exhaustive)
Represents a scheduler that will execute tasks with a precision based on its ticking rate. If precision is important, consider using a JDK executor service or any third party library.

Tasks are by default executed in the caller thread.

  • Method Details Link icon

    • newScheduler Link icon

      @NotNull static @NotNull Scheduler newScheduler()
    • process Link icon

      void process()
      Process scheduled tasks based on time to increase scheduling precision.

      This method is not thread-safe.

    • processTick Link icon

      void processTick()
      Advance 1 tick and call process().

      This method is not thread-safe.

    • processTickEnd Link icon

      void processTickEnd()
      Execute tasks set to run at the end of this tick.

      This method is not thread-safe.

    • submitTask Link icon

      @NotNull @NotNull Task submitTask(@NotNull @NotNull Supplier<TaskSchedule> task, @NotNull @NotNull ExecutionType executionType)
      Submits a new task with custom scheduling logic.

      This is the primitive method used by all scheduling shortcuts, task is immediately executed in the caller thread to retrieve its scheduling state and the task will stay alive as long as TaskSchedule.stop() is not returned (or Task.cancel() is called).

      Parameters:
      task - the task to be directly executed in the caller thread
      executionType - the execution type
      Returns:
      the created task
    • submitTask Link icon

      @NotNull default @NotNull Task submitTask(@NotNull @NotNull Supplier<TaskSchedule> task)
    • buildTask Link icon

      @NotNull default Task.Builder buildTask(@NotNull @NotNull Runnable task)
    • scheduleTask Link icon

      @NotNull default @NotNull Task scheduleTask(@NotNull @NotNull Runnable task, @NotNull @NotNull TaskSchedule delay, @NotNull @NotNull TaskSchedule repeat, @NotNull @NotNull ExecutionType executionType)
    • scheduleTask Link icon

      @NotNull default @NotNull Task scheduleTask(@NotNull @NotNull Runnable task, @NotNull @NotNull TaskSchedule delay, @NotNull @NotNull TaskSchedule repeat)
    • scheduleTask Link icon

      @NotNull default @NotNull Task scheduleTask(@NotNull @NotNull Supplier<TaskSchedule> task, @NotNull @NotNull TaskSchedule delay)
    • scheduleNextTick Link icon

      @NotNull default @NotNull Task scheduleNextTick(@NotNull @NotNull Runnable task, @NotNull @NotNull ExecutionType executionType)
    • scheduleNextTick Link icon

      @NotNull default @NotNull Task scheduleNextTick(@NotNull @NotNull Runnable task)
    • scheduleEndOfTick Link icon

      @NotNull default @NotNull Task scheduleEndOfTick(@NotNull @NotNull Runnable task)
    • scheduleNextProcess Link icon

      @NotNull default @NotNull Task scheduleNextProcess(@NotNull @NotNull Runnable task, @NotNull @NotNull ExecutionType executionType)
    • scheduleNextProcess Link icon

      @NotNull default @NotNull Task scheduleNextProcess(@NotNull @NotNull Runnable task)
    • execute Link icon

      default void execute(@NotNull @NotNull Runnable command)
      Implementation of Executor, proxies to scheduleNextTick(Runnable).
      Specified by:
      execute in interface Executor
      Parameters:
      command - the task to execute on the next tick