Scheduler extends Executor for convenience (#2036)

* Scheduler extends Executor for convenience

* chore: doc on Scheduler#execute()

---------

Co-authored-by: mworzala <mattheworzala@gmail.com>
This commit is contained in:
Samuel 2024-03-21 17:05:12 -04:00 committed by GitHub
parent a31d239b51
commit 1058d88552
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package net.minestom.server.timer;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
/**
@ -10,7 +11,7 @@ import java.util.function.Supplier;
* <p>
* Tasks are by default executed in the caller thread.
*/
public sealed interface Scheduler permits SchedulerImpl, SchedulerManager {
public sealed interface Scheduler extends Executor permits SchedulerImpl, SchedulerManager {
static @NotNull Scheduler newScheduler() {
return new SchedulerImpl();
}
@ -75,4 +76,13 @@ public sealed interface Scheduler permits SchedulerImpl, SchedulerManager {
default @NotNull Task scheduleNextProcess(@NotNull Runnable task) {
return scheduleNextProcess(task, ExecutionType.SYNC);
}
/**
* Implementation of {@link Executor}, proxies to {@link #scheduleNextTick(Runnable)}.
* @param command the task to execute on the next tick
*/
@Override
default void execute(@NotNull Runnable command) {
scheduleNextTick(command);
}
}