Class TaskScheduler

java.lang.Object
io.github.thecsdev.tcdcommons.api.util.thread.TaskScheduler

public final class TaskScheduler extends Object
A utility that provides methods for scheduling tasks that can then be executed later on Minecraft's main Thread.
  • Method Details

    • schedulePeriodicCacheCleanup

      public static <K, V> com.google.common.cache.Cache<K,V> schedulePeriodicCacheCleanup(com.google.common.cache.Cache<K,V> cache) throws NullPointerException
      Schedules a task that periodically cleans up a Cache object.
      Parameters:
      cache - The Cache object to start cleaning up periodically.
      Returns:
      The Cache object that was passed as the argument.
      Throws:
      NullPointerException - If the argument is null.
      See Also:
    • cancelPeriodicCacheCleanup

      public static void cancelPeriodicCacheCleanup(com.google.common.cache.Cache<?,?> cache)
      If you have scheduled a task to periodically clean up a Cache object, you can cancel that task here.
      Parameters:
      cache - The Cache object to stop cleaning up periodically.
      See Also:
    • scheduleTask

      public static void scheduleTask(net.minecraft.util.thread.ReentrantThreadExecutor<?> minecraftClientOrServer, long delay, TimeUnit unit, Runnable command) throws NullPointerException
      Schedules a task to be executed on the ReentrantThreadExecutor some time in the future.
      Throws:
      NullPointerException
    • executeOnce

      @Experimental public static void executeOnce(net.minecraft.util.thread.ReentrantThreadExecutor<?> minecraftClientOrServer, BooleanSupplier condition, Runnable command) throws NullPointerException
      Schedules a task to be executed on the ReentrantThreadExecutor once a given condition is met, aka once the BooleanSupplier returns true. Once the task is executed, it will never be executed again.
      Throws:
      NullPointerException
    • executeProgressiveTask

      public static void executeProgressiveTask(ProgressiveTask<?> task) throws IllegalStateException
      Executes a ProgressiveTask asynchronously.
      Parameters:
      task - The ProgressiveTask to execute.
      Throws:
      IllegalStateException - If the ProgressiveTask is already being executed.