Fast exit if task queue is empty

This commit is contained in:
themode 2021-12-16 16:07:07 +01:00 committed by TheMode
parent 5c6d0dc7b2
commit 9af41f944a

View File

@ -53,13 +53,15 @@ final class SchedulerImpl implements Scheduler {
}
}
// Run all tasks lock-free, either in the current thread or pool
this.taskQueue.drain(task -> {
if (!task.isAlive()) return;
switch (task.executionType()) {
case SYNC -> handleTask(task);
case ASYNC -> EXECUTOR.submit(() -> handleTask(task));
}
});
if (!taskQueue.isEmpty()) {
this.taskQueue.drain(task -> {
if (!task.isAlive()) return;
switch (task.executionType()) {
case SYNC -> handleTask(task);
case ASYNC -> EXECUTOR.submit(() -> handleTask(task));
}
});
}
}
@Override