Class ImmediateThinScheduler


  • public final class ImmediateThinScheduler
    extends Scheduler
    A Scheduler partially implementing the API by allowing only non-delayed, non-periodic task execution on the current thread immediately.

    Note that this doesn't support recursive scheduling and disposing the returned Disposable has no effect (because when the schedule() method returns, the task has been already run).

    • Field Detail

      • INSTANCE

        public static final Scheduler INSTANCE
        The singleton instance of the immediate (thin) scheduler.
    • Constructor Detail

      • ImmediateThinScheduler

        private ImmediateThinScheduler()
    • Method Detail

      • scheduleDirect

        @NonNull
        public @NonNull Disposable scheduleDirect​(@NonNull
                                                  @NonNull java.lang.Runnable run)
        Description copied from class: Scheduler
        Schedules the given task on this Scheduler without any time delay.

        This method is safe to be called from multiple threads but there are no ordering or non-overlapping guarantees between tasks.

        Overrides:
        scheduleDirect in class Scheduler
        Parameters:
        run - the task to execute
        Returns:
        the Disposable instance that let's one cancel this particular task.
      • scheduleDirect

        @NonNull
        public @NonNull Disposable scheduleDirect​(@NonNull
                                                  @NonNull java.lang.Runnable run,
                                                  long delay,
                                                  java.util.concurrent.TimeUnit unit)
        Description copied from class: Scheduler
        Schedules the execution of the given task with the given time delay.

        This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.

        Overrides:
        scheduleDirect in class Scheduler
        Parameters:
        run - the task to schedule
        delay - the delay amount, non-positive values indicate non-delayed scheduling
        unit - the unit of measure of the delay amount
        Returns:
        the Disposable that let's one cancel this particular delayed task.
      • schedulePeriodicallyDirect

        @NonNull
        public @NonNull Disposable schedulePeriodicallyDirect​(@NonNull
                                                              @NonNull java.lang.Runnable run,
                                                              long initialDelay,
                                                              long period,
                                                              java.util.concurrent.TimeUnit unit)
        Description copied from class: Scheduler
        Schedules a periodic execution of the given task with the given initial time delay and repeat period.

        This method is safe to be called from multiple threads but there are no ordering guarantees between tasks.

        The periodic execution is at a fixed rate, that is, the first execution will be after the initialDelay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

        Overrides:
        schedulePeriodicallyDirect in class Scheduler
        Parameters:
        run - the task to schedule
        initialDelay - the initial delay amount, non-positive values indicate non-delayed scheduling
        period - the period at which the task should be re-executed
        unit - the unit of measure of the delay amount
        Returns:
        the Disposable that let's one cancel this particular delayed task.
      • createWorker

        @NonNull
        public @NonNull Scheduler.Worker createWorker()
        Description copied from class: Scheduler
        Retrieves or creates a new Scheduler.Worker that represents sequential execution of actions.

        When work is completed, the Worker instance should be released by calling Disposable.dispose() to avoid potential resource leaks in the underlying task-execution scheme.

        Work on a Scheduler.Worker is guaranteed to be sequential and non-overlapping.

        Specified by:
        createWorker in class Scheduler
        Returns:
        a Worker representing a serial queue of actions to be executed