Interface IExecutor
- All Known Implementing Classes:
ExecutorSpigot
public interface IExecutor
Represents an interface that allows scheduling (a)sync tasks.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAsserts that this method was called from the main thread.default voidassertMainThread(String message) Asserts that this method was called from the main thread.default voidAsserts that this method was not called from the main thread.default voidassertNotMainThread(String message) Asserts that this method was not called from the main thread.voidCancels a task.default <T> CompletableFuture<T> composeOnMainThread(Supplier<CompletableFuture<T>> supplier) Ensures a supplier is run on the main thread.default booleanChecks if the current thread is the main thread.booleanisMainThread(long threadId) Checks if a thread is the main thread.intSchedules an action to be run asynchronously.voidrunAsyncLater(Runnable runnable, long delay) Schedules a repeatedRunnableto be run asynchronously.voidrunAsyncLater(TimerTask timerTask, long delay) Schedules a repeatedTimerTaskto be run asynchronously.intrunAsyncRepeated(Runnable runnable, long delay, long period) Schedules a repeatedRunnableto be run asynchronously.intrunAsyncRepeated(TimerTask timerTask, long delay, long period) Schedules a repeatedTimerTaskto be run asynchronously.default voidrunOnMainThread(Runnable runnable) Ensures a runnable is run on the main thread.default <T> CompletableFuture<T> runOnMainThread(Supplier<T> supplier) Ensures a supplier is run on the main thread.default CompletableFuture<Void> runOnMainThreadWithResponse(Runnable runnable) Ensures a runnable is run on the main thread.intSchedules an action to be run on the main thread.voidrunSyncLater(Runnable runnable, long delay) Schedules a repeatedRunnableto be run on the main thread.voidrunSyncLater(TimerTask timerTask, long delay) Schedules a repeatedTimerTaskto be run on the main thread.intrunSyncRepeated(Runnable runnable, long delay, long period) Schedules a repeatedRunnableto be run on the main thread.intrunSyncRepeated(TimerTask timerTask, long delay, long period) Schedules a repeatedTimerTaskto be run on the main thread.voidscheduleOnMainThread(Runnable runnable) Schedules an action to be run on the main thread.<T> CompletableFuture<T> scheduleOnMainThread(Supplier<T> supplier) Schedules a task to be run on the main thread.<T> CompletableFuture<T> supplyAsync(Supplier<T> supplier) Schedules a task to be run on the main thread.
-
Method Details
-
scheduleOnMainThread
Schedules a task to be run on the main thread.- Parameters:
supplier- A function returning the value to be used to complete the returned IMainThreadExecutor.- Returns:
- The result of the action.
-
runOnMainThread
Ensures a supplier is run on the main thread.When called from the main thread, it will be executed immediately. When called from another thread, the supplier is scheduled to run on the next tick of the main thread instead.
- Returns:
- The result of the action.
-
composeOnMainThread
Ensures a supplier is run on the main thread.When called from the main thread, it will be executed immediately. When called from another thread, the supplier is scheduled to run on the next tick of the main thread instead.
- Type Parameters:
T- The type of the result.- Parameters:
supplier- The supplier to run.- Returns:
- The result of the action.
-
runOnMainThreadWithResponse
Ensures a runnable is run on the main thread.When called from the main thread, it will be executed immediately. When called from another thread, the supplier is scheduled to run on the next tick of the main thread instead.
- Returns:
- The CompletableFuture that is completed when the runnable has finished running.
-
scheduleOnMainThread
Schedules an action to be run on the main thread. -
runOnMainThread
Ensures a runnable is run on the main thread.When called from the main thread, it will be executed immediately. When called from another thread, the supplier is scheduled to run on the next tick of the main thread instead.
-
supplyAsync
Schedules a task to be run on the main thread.- Parameters:
supplier- A function returning the value to be used to complete the returned IMainThreadExecutor.- Returns:
- The result of the action.
-
runAsync
Schedules an action to be run asynchronously.- Parameters:
runnable- The action to run.- Returns:
- The ID of the task.
-
runSync
Schedules an action to be run on the main thread.- Parameters:
runnable- The action to run.- Returns:
- The ID of the task.
-
runAsyncRepeated
Schedules a repeatedTimerTaskto be run asynchronously.- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runAsyncRepeated
Schedules a repeatedRunnableto be run asynchronously.- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runSyncRepeated
Schedules a repeatedTimerTaskto be run on the main thread.- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runSyncRepeated
Schedules a repeatedRunnableto be run on the main thread.- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.period- The time in milliseconds between successive task executions.- Returns:
- The ID of the task.
-
runAsyncLater
Schedules a repeatedTimerTaskto be run asynchronously.- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runAsyncLater
Schedules a repeatedRunnableto be run asynchronously.- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runSyncLater
Schedules a repeatedTimerTaskto be run on the main thread.- Parameters:
timerTask- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
runSyncLater
Schedules a repeatedRunnableto be run on the main thread.- Parameters:
runnable- The task to run.delay- The delay in milliseconds before the task is to be executed.
-
cancel
Cancels a task.- Parameters:
timerTask- The task that is to be cancelled.taskID- The ID assigned to the task.
-
isMainThread
boolean isMainThread(long threadId) Checks if a thread is the main thread.- Parameters:
threadId- The ID of the thread to compare.- Returns:
- True if the thread is the main thread.
-
isMainThread
default boolean isMainThread()Checks if the current thread is the main thread.- Returns:
- True if the current thread is the main thread.
-
assertMainThread
Asserts that this method was called from the main thread. SeeisMainThread().- Parameters:
message- The error message for the exception.- Throws:
IllegalStateException- When called from any thread that is not that main thread.
-
assertMainThread
default void assertMainThread()Asserts that this method was called from the main thread. SeeisMainThread().- Throws:
IllegalStateException- When called from any thread that is not that main thread.
-
assertNotMainThread
Asserts that this method was not called from the main thread. SeeisMainThread().- Parameters:
message- The error message for the exception.- Throws:
IllegalStateException- When called from the main thread.
-
assertNotMainThread
default void assertNotMainThread()Asserts that this method was not called from the main thread. SeeisMainThread().- Throws:
IllegalStateException- When called from the main thread.
-