Skip to content

Commit

Permalink
avoid freezing if _SendMessage overtime when ClientImpl::ProcessKeyEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed May 23, 2024
1 parent a439ac7 commit b1aebe8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions WeaselIPC/WeaselClientImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "stdafx.h"
#include "WeaselClientImpl.h"
#include <StringAlgorithm.hpp>
#include <future>
#include <chrono>

using namespace weasel;

Expand Down Expand Up @@ -59,9 +61,20 @@ bool ClientImpl::ProcessKeyEvent(KeyEvent const& keyEvent) {
if (!_Active())
return false;

LRESULT ret =
_SendMessage(WEASEL_IPC_PROCESS_KEY_EVENT, keyEvent, session_id);
return ret != 0;
// create async task _SendMessage
auto future = std::async(std::launch::async, [this, &keyEvent]() {
return _SendMessage(WEASEL_IPC_PROCESS_KEY_EVENT, keyEvent, session_id);
});

// wait _SendMessage complete or overtime
if (future.wait_for(std::chrono::seconds(2)) == std::future_status::timeout) {
// _SendMessage overtime
return false;
} else {
// _SendMessage complete
LRESULT ret = future.get();
return ret != 0;
}
}

bool ClientImpl::CommitComposition() {
Expand Down

0 comments on commit b1aebe8

Please sign in to comment.