Skip to content

Commit

Permalink
fix: Fix race condition on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwmtr committed Nov 3, 2024
1 parent 471df3c commit b4131ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/core/co_initialize/co_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,16 @@ void OnBackendLoad(uint16_t ftpPort, uint16_t ipcPort)
Logger.Log("Frontend notifier finished!");
}

const void CoInitializer::InjectFrontendShims(uint16_t ftpPort, uint16_t ipcPort) {
const void CoInitializer::InjectFrontendShims(uint16_t ftpPort, uint16_t ipcPort)
{
std::mutex mtx;
std::condition_variable cv;
bool hasSuccess = false, hasPaused = false;

Logger.Log("Preparing to inject frontend shims...");

JavaScript::SharedJSMessageEmitter::InstanceRef().OnMessage("msg", [&](const nlohmann::json& eventMessage, int listenerId) {
JavaScript::SharedJSMessageEmitter::InstanceRef().OnMessage("msg", [&](const nlohmann::json& eventMessage, int listenerId)
{
std::lock_guard<std::mutex> lock(mtx);

if (eventMessage.value("id", -1) == 65756)
Expand Down
2 changes: 1 addition & 1 deletion src/core/ffi/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace JavaScript {
auto it = missedMessages.find(event);
if (it != missedMessages.end()) {
for (const auto message : it->second) {
std::thread([handler, message, listenerId] { handler(message, listenerId); }).detach();
handler(message, listenerId);
}
missedMessages.erase(it); // Clear missed messages once delivered
}
Expand Down

0 comments on commit b4131ef

Please sign in to comment.