Class SimpleAsyncExecutor

java.lang.Object
me.moros.tasker.executor.SimpleAsyncExecutor
All Implemented Interfaces:
Executor, AsyncExecutor, TaskExecutor, TickAdapter

public class SimpleAsyncExecutor extends Object implements AsyncExecutor
A simple async executor implementation that delegates to a ScheduledExecutorService for repeated tasks.
  • Constructor Details

    • SimpleAsyncExecutor

      public SimpleAsyncExecutor(ExecutorService executor)
    • SimpleAsyncExecutor

      public SimpleAsyncExecutor()
  • Method Details

    • submit

      public <V> CompletableFuture<@PolyNull V> submit(Supplier<@PolyNull V> task, long delay, TimeUnit unit)
      Description copied from interface: TaskExecutor
      Submit a task.
      Specified by:
      submit in interface TaskExecutor
      Type Parameters:
      V - the type of result the task returns
      Parameters:
      task - the task to submit
      delay - the delay before the task is executed
      unit - the unit of time for delay
      Returns:
      the scheduled task as a future
    • repeat

      public Task repeat(Runnable task, long delay, long period, TimeUnit unit)
      Description copied from interface: TaskExecutor
      Schedule a repeating task.
      Specified by:
      repeat in interface TaskExecutor
      Parameters:
      task - the task to schedule
      delay - the delay before the first task execution
      period - how often to repeat the task
      unit - the unit of time for delay and period
      Returns:
      the scheduled task
    • isValid

      public boolean isValid()
      Description copied from interface: TaskExecutor
      Check whether this executor can currently schedule and execute tasks. This should return false if it hasn't been initialized or has been terminated.
      Specified by:
      isValid in interface TaskExecutor
      Returns:
      whether tasks can be scheduled and executed
    • shutdown

      public void shutdown()
      Description copied from interface: TaskExecutor
      Safely shutdown this executor.
      Specified by:
      shutdown in interface TaskExecutor
    • checkValid

      protected void checkValid()