mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
update app.sleep_until
This commit is contained in:
parent
9fe26cc18d
commit
95818f576b
1 changed files with 9 additions and 2 deletions
|
|
@ -79,13 +79,20 @@ local function complete_app_lib(app)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
function app.sleep_until(predicate, max_ticks)
|
function app.sleep_until(predicate, max_ticks, max_time)
|
||||||
max_ticks = max_ticks or 1e9
|
max_ticks = max_ticks or 1e9
|
||||||
|
max_time = max_time or 1e9
|
||||||
local ticks = 0
|
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()
|
app.tick()
|
||||||
ticks = ticks + 1
|
ticks = ticks + 1
|
||||||
end
|
end
|
||||||
|
if os.clock() - start_time >= max_time then
|
||||||
|
error("timeout")
|
||||||
|
end
|
||||||
if ticks == max_ticks then
|
if ticks == max_ticks then
|
||||||
error("max ticks exceed")
|
error("max ticks exceed")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue