refactor: use the executor service for eval bridge functions

This commit is contained in:
ChomeNS
2025-04-21 20:28:48 +07:00
parent f1d24b8a59
commit 8b4286bc31
2 changed files with 12 additions and 8 deletions

View File

@@ -60,15 +60,19 @@ public class EvalPlugin {
socket.on(Socket.EVENT_CONNECT_ERROR, (args) -> connected = false);
for (final EvalFunction function : functions) {
socket.on(BRIDGE_PREFIX + function.name, args -> new Thread(() -> {
try {
final EvalFunction.Output output = function.execute(args);
socket.on(
BRIDGE_PREFIX + function.name,
args ->
bot.executorService.submit(() -> {
try {
final EvalFunction.Output output = function.execute(args);
if (output == null) return;
if (output == null) return;
socket.emit("functionOutput:" + function.name, output.message(), output.parseJSON());
} catch (final Exception ignored) { }
}).start());
socket.emit("functionOutput:" + function.name, output.message(), output.parseJSON());
} catch (final Exception ignored) { }
})
);
}
socket.on("codeOutput", (args) -> {