Class TaskScheduler
java.lang.Object
io.github.thecsdev.tcdcommons.api.util.thread.TaskScheduler
A utility that provides methods for scheduling tasks that can
then be executed later on Minecraft's main
Thread
.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
cancelPeriodicCacheCleanup
(com.google.common.cache.Cache<?, ?> cache) If you have scheduled a task to periodically clean up aCache
object, you can cancel that task here.static void
executeOnce
(net.minecraft.util.thread.ReentrantThreadExecutor<?> minecraftClientOrServer, BooleanSupplier condition, Runnable command) Schedules a task to be executed on theReentrantThreadExecutor
once a given condition is met, aka once theBooleanSupplier
returnstrue
.static void
executeProgressiveTask
(ProgressiveTask<?> task) Executes aProgressiveTask
asynchronously.static <K,
V> com.google.common.cache.Cache <K, V> schedulePeriodicCacheCleanup
(com.google.common.cache.Cache<K, V> cache) Schedules a task that periodically cleans up aCache
object.static void
scheduleTask
(net.minecraft.util.thread.ReentrantThreadExecutor<?> minecraftClientOrServer, long delay, TimeUnit unit, Runnable command) Schedules a task to be executed on theReentrantThreadExecutor
some time in the future.
-
Method Details
-
schedulePeriodicCacheCleanup
public static <K,V> com.google.common.cache.Cache<K,V> schedulePeriodicCacheCleanup(com.google.common.cache.Cache<K, V> cache) throws NullPointerExceptionSchedules a task that periodically cleans up aCache
object.- Parameters:
cache
- TheCache
object to start cleaning up periodically.- Returns:
- The
Cache
object that was passed as the argument. - Throws:
NullPointerException
- If the argument isnull
.- See Also:
-
cancelPeriodicCacheCleanup
public static void cancelPeriodicCacheCleanup(com.google.common.cache.Cache<?, ?> cache) If you have scheduled a task to periodically clean up aCache
object, you can cancel that task here.- Parameters:
cache
- TheCache
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 theReentrantThreadExecutor
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 theReentrantThreadExecutor
once a given condition is met, aka once theBooleanSupplier
returnstrue
. Once the task is executed, it will never be executed again.- Throws:
NullPointerException
-
executeProgressiveTask
Executes aProgressiveTask
asynchronously.- Parameters:
task
- TheProgressiveTask
to execute.- Throws:
IllegalStateException
- If theProgressiveTask
is already being executed.
-