mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 03:27:56 +01:00
Add Scheduler#scheduleNextProcess
This commit is contained in:
parent
389f028137
commit
2d1102e0e8
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user