fix commands execution thread

This commit is contained in:
MihailRis 2026-02-11 23:58:42 +03:00
parent 4478afa1ef
commit 48f5de8adf
3 changed files with 18 additions and 16 deletions

View file

@ -1,5 +1,6 @@
#include "stdin_reader.hpp" #include "stdin_reader.hpp"
#include "engine/Engine.hpp"
#include "logic/CommandsInterpreter.hpp" #include "logic/CommandsInterpreter.hpp"
#include "coders/json.hpp" #include "coders/json.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
@ -11,8 +12,9 @@ static debug::Logger logger("stdin-reader");
static std::thread reader_thread; static std::thread reader_thread;
void start_stdin_reader(cmd::CommandsInterpreter& interpreter) { void start_stdin_reader(Engine& engine) {
reader_thread = std::thread([&interpreter]() { reader_thread = std::thread([&engine]() {
auto& interpreter = engine.getCmd();
logger.info() << "reader thread started"; logger.info() << "reader thread started";
std::string line; std::string line;
@ -20,6 +22,7 @@ void start_stdin_reader(cmd::CommandsInterpreter& interpreter) {
if (line.empty()) { if (line.empty()) {
continue; continue;
} }
engine.postRunnable([line, &interpreter] () {
try { try {
auto result = interpreter.execute(line); auto result = interpreter.execute(line);
if (result.isString()) { if (result.isString()) {
@ -30,6 +33,7 @@ void start_stdin_reader(cmd::CommandsInterpreter& interpreter) {
} catch (const std::exception& err) { } catch (const std::exception& err) {
logger.error() << err.what(); logger.error() << err.what();
} }
});
} }
}); });
reader_thread.detach(); reader_thread.detach();

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
namespace cmd { class Engine;
class CommandsInterpreter;
}
void start_stdin_reader(cmd::CommandsInterpreter& interpreter); void start_stdin_reader(Engine& engine);

View file

@ -193,7 +193,7 @@ void Engine::initialize(CoreParameters coreParameters) {
project->loadProjectClientScript(); project->loadProjectClientScript();
} }
if (params.stdinCommands) { if (params.stdinCommands) {
start_stdin_reader(*cmd); start_stdin_reader(*this);
} }
} }