mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
Add timeout to WaitForAll
This commit is contained in:
parent
86169ad0fa
commit
a289d0e872
@ -105,7 +105,8 @@ public:
|
||||
return LuaEventsCount - GetLuaStateCount();
|
||||
}
|
||||
|
||||
static void WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results);
|
||||
static void WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results,
|
||||
const std::chrono::high_resolution_clock::duration& Max = std::chrono::hours(std::numeric_limits<size_t>().max()));
|
||||
void ReportErrors(const std::vector<std::shared_ptr<TLuaResult>>& Results);
|
||||
bool HasState(TLuaStateId StateId);
|
||||
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(TLuaStateId StateID, const TLuaChunk& Script);
|
||||
|
@ -145,10 +145,16 @@ TLuaStateId TLuaEngine::GetStateIDForPlugin(const fs::path& PluginPath) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results) {
|
||||
void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, const std::chrono::high_resolution_clock::duration& max) {
|
||||
size_t ms = 0;
|
||||
bool Cancelled = false;
|
||||
for (const auto& Result : Results) {
|
||||
while (!Result->Ready) {
|
||||
while (!Result->Ready && !Cancelled) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
ms += 10;
|
||||
if (std::chrono::milliseconds(ms) > max) {
|
||||
Cancelled = true;
|
||||
}
|
||||
}
|
||||
if (Result->Error) {
|
||||
if (Result->ErrorMessage != BeamMPFnNotFoundError) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user