From 95818f576bf8761c38c3feb0e9e90110990aa76b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 14 Sep 2025 15:11:39 +0300 Subject: [PATCH] update app.sleep_until --- res/scripts/stdlib.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 1243085b..b07d9387 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -79,13 +79,20 @@ local function complete_app_lib(app) coroutine.yield() end - function app.sleep_until(predicate, max_ticks) + function app.sleep_until(predicate, max_ticks, max_time) max_ticks = max_ticks or 1e9 + max_time = max_time or 1e9 local ticks = 0 - while ticks < max_ticks and not predicate() do + local start_time = os.clock() + while ticks < max_ticks and + os.clock() - start_time < max_time + and not predicate() do app.tick() ticks = ticks + 1 end + if os.clock() - start_time >= max_time then + error("timeout") + end if ticks == max_ticks then error("max ticks exceed") end