Package com.jozufozu.flywheel.api.task
Interface TaskExecutor
- All Superinterfaces:
Executor
- All Known Implementing Classes:
ParallelTaskExecutor,SerialTaskExecutor
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck whether the current thread is this task executor's main thread.voidscheduleForMainThread(Runnable runnable) Schedule a task to be run on the main thread.voidWait for all running tasks to finish.booleansyncUntil(BooleanSupplier cond) Wait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).booleansyncWhile(BooleanSupplier cond) Wait for running tasks, so long as the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).intCheck for the number of threads this executor uses.
-
Method Details
-
syncPoint
void syncPoint()Wait for all running tasks to finish.
This is useful as a nuclear option, but most of the time you should try to usesyncUntil. -
syncUntil
Wait for running tasks, until the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).
This method is equivalent tosyncWhile(() -> !cond.getAsBoolean()).- Parameters:
cond- The condition to wait for.- Returns:
trueif the condition is met.falseif this executor runs out of tasks before the condition is met.
-
syncWhile
Wait for running tasks, so long as the given condition is met (BooleanSupplier.getAsBoolean()returnstrue).
If this method is called on the
This method is equivalent tosyncUntil(() -> !cond.getAsBoolean()).- Parameters:
cond- The condition sync on.- Returns:
trueif the condition is no longer met.falseif this executor runs out of tasks while the condition is still met.
-
scheduleForMainThread
Schedule a task to be run on the main thread.
This method may be called from any thread (including the main thread), but the runnable will only be executed once somebody calls eithersyncPoint()orsyncUntil(BooleanSupplier)on this task executor's main thread.- Parameters:
runnable- The task to run.
-
isMainThread
boolean isMainThread()Check whether the current thread is this task executor's main thread.- Returns:
trueif the current thread is the main thread.
-
threadCount
int threadCount()Check for the number of threads this executor uses.
May be helpful when determining how many chunks to divide a task into.- Returns:
- The number of threads this executor uses.
-