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 // Run all tasks lock-free, either in the current thread or pool
this.taskQueue.drain(task -> { if (!taskQueue.isEmpty()) {
if (!task.isAlive()) return; this.taskQueue.drain(task -> {
switch (task.executionType()) { if (!task.isAlive()) return;
case SYNC -> handleTask(task); switch (task.executionType()) {
case ASYNC -> EXECUTOR.submit(() -> handleTask(task)); case SYNC -> handleTask(task);
} case ASYNC -> EXECUTOR.submit(() -> handleTask(task));
}); }
});
}
} }
@Override @Override