Interface TaskScheduler

All Superinterfaces:
Entity, RequiresCatnip
All Known Implementing Classes:
AbstractTaskScheduler, RxTaskScheduler

public interface TaskScheduler extends RequiresCatnip
A basic task scheduler to replace vert.x's setTimer() and setPeriodic(). The default implementation is RxTaskScheduler, which is a basic wrapper over Observable.timer(long, TimeUnit) and Observable.interval(long, TimeUnit).
Since:
7/29/19.
Author:
amy
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    cancel(long id)
    Cancels the task with the supplied id.
    long
    setInterval(long ms, Consumer<Long> task)
    Schedules a new task to be run on an interval.
    long
    setTimer(long ms, Consumer<Long> task)
    Schedules a new task to be run in the future.

    Methods inherited from interface com.mewna.catnip.entity.Entity

    catnip, serialize

    Methods inherited from interface com.mewna.catnip.entity.RequiresCatnip

    catnip
  • Method Details

    • setTimer

      @Nonnegative long setTimer(@Nonnegative long ms, @Nonnull Consumer<Long> task)
      Schedules a new task to be run in the future.
      Parameters:
      ms - Delay, in milliseconds, before the task is run.
      task - The task to be run.
      Returns:
      The id of the task to be run. Used for cancellations.
    • setInterval

      @Nonnegative long setInterval(@Nonnegative long ms, @Nonnull Consumer<Long> task)
      Schedules a new task to be run on an interval.
      Parameters:
      ms - Interval, in milliseconds, between task runs.
      task - The task to be run.
      Returns:
      The id of the task to be run. Used for cancellations.
    • cancel

      boolean cancel(@Nonnegative long id)
      Cancels the task with the supplied id.
      Parameters:
      id - The id of the task to cancel.
      Returns:
      true if the task was successfully cancelled, false otherwise.