Add Scheduler#scheduleNextProcess

This commit is contained in:
themode 2021-12-22 13:04:12 +01:00 committed by TheMode
parent 389f028137
commit 2d1102e0e8
2 changed files with 22 additions and 0 deletions

View File

@ -67,4 +67,12 @@ public sealed interface Scheduler permits SchedulerImpl, SchedulerManager {
default @NotNull Task scheduleNextTick(@NotNull Runnable task) {
return scheduleNextTick(task, ExecutionType.SYNC);
}
default @NotNull Task scheduleNextProcess(@NotNull Runnable task, @NotNull ExecutionType executionType) {
return buildTask(task).delay(TaskSchedule.immediate()).executionType(executionType).schedule();
}
default @NotNull Task scheduleNextProcess(@NotNull Runnable task) {
return scheduleNextProcess(task, ExecutionType.SYNC);
}
}

View File

@ -43,6 +43,20 @@ public class TestScheduler {
assertTrue(result.get(), "Tick task must be executed after 1 second");
}
@Test
public void immediateTask() {
Scheduler scheduler = Scheduler.newScheduler();
AtomicBoolean result = new AtomicBoolean(false);
scheduler.scheduleNextProcess(() -> result.set(true));
assertFalse(result.get());
scheduler.process();
assertTrue(result.get());
result.set(false);
scheduler.process();
assertFalse(result.get());
}
@Test
public void cancelTask() {
Scheduler scheduler = Scheduler.newScheduler();