Skip to content

Commit c2dbc5e

Browse files
committed
Refactor getSyncExecutor to improve synchronous task execution fallback
1 parent 24a1076 commit c2dbc5e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

common/src/main/java/it/renvins/serverpulse/common/scheduler/TaskScheduler.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,20 @@ default Task runTaskLater(Runnable task, long delayTicks) {
5757
*/
5858
Task runTaskLaterAsync(Runnable task, long delayTicks);
5959

60+
/**
61+
* Returns an Executor that runs tasks synchronously on the main thread
62+
* or falls back to asynchronous execution if sync is not supported.
63+
*
64+
* @return An Executor for synchronous task execution
65+
*/
6066
default Executor getSyncExecutor() {
61-
try {
62-
return this::runSync;
63-
} catch (UnsupportedOperationException e) {
64-
return this::runAsync;
65-
}
67+
return task -> {
68+
try {
69+
runSync(task);
70+
} catch (UnsupportedOperationException e) {
71+
// Fallback to async execution if sync is not supported
72+
runAsync(task);
73+
}
74+
};
6675
}
6776
}

0 commit comments

Comments
 (0)