Class Scheduler<T>

java.lang.Object
dev.bouncingelf10.timelesslib.api.scheduler.Scheduler<T>

public class Scheduler<T> extends Object
  • Constructor Details

  • Method Details

    • after

      public TaskHandle after(Duration delay, Consumer<T> task)
      Schedules a task to run after the specified delay.
      Parameters:
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
    • after

      public TaskHandle after(String id, Duration delay, Consumer<T> task)
      Schedules a task to run after the specified delay.
      Parameters:
      id - Unique ID for the task
      delay - Delay before running the task
      task - Task to run
      Returns:
      TaskHandle
      Throws:
      IllegalArgumentException - if a task with the specified ID already exists
    • every

      public TaskHandle every(Duration period, Consumer<T> task)
      Schedules a repeating task to run at the specified interval.
      Parameters:
      period - Interval between runs
      task - Task to run
      Returns:
      TaskHandle
    • everyFixedRate

      public TaskHandle everyFixedRate(Duration period, Consumer<T> task)
      Schedules a repeating task to run at the specified interval, with a fixed delay between runs.
      E.g. every(Duration, Consumer) will run the interval after the task has finished executing, whereas this method will run the interval immediately after the task starts executing.
      Parameters:
      period -
      task -
      Returns:
      TaskHandle
    • afterAsync

      public CompletableFuture<Void> afterAsync(Duration delay, Consumer<T> task)
      Schedules a task to run after the specified delay, returning a CompletableFuture that completes when the task has finished executing.
      Parameters:
      delay - Delay before running the task
      task - Task to run
      Returns:
      CompletableFuture
    • shutdown

      public void shutdown()
      If you're getting the scheduler through TimelessLib.getServerScheduler() or the client counterpart you should NOT call this method.
    • shutdownGracefully

      public void shutdownGracefully(long timeout, TimeUnit unit) throws InterruptedException
      If you're getting the scheduler through TimelessLib.getServerScheduler() or the client counterpart you should NOT call this method.
      Throws:
      InterruptedException
    • isShutdown

      public boolean isShutdown()
    • isTerminated

      public boolean isTerminated()