From 40beef755f0c47691b5cd5a79e76fdd361320aa8 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 21 Nov 2021 16:37:08 +0100 Subject: Sleep for unused tick time & optional realtime - Optional luasocket dependency for realtime measurements (instead of CPU time) - lua_async.run() will wait for the time to be ready --- limiting.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'limiting.lua') diff --git a/limiting.lua b/limiting.lua index d5df448..394006d 100644 --- a/limiting.lua +++ b/limiting.lua @@ -13,7 +13,7 @@ function lua_async.set_limit(ms) lua_async.limiting.pool[co] = { limit = limit, - next_yield = os.clock() + limit, + next_yield = lua_async.clock() + limit, } end @@ -26,9 +26,9 @@ function lua_async.check_limit() local co = assert(coroutine.running(), "check_limit called outside of an async function") local limit = lua_async.limiting.pool[co] - if limit and os.clock() >= limit.next_yield then + if limit and lua_async.clock() >= limit.next_yield then lua_async.yield() - limit.next_yield = os.clock() + limit.limit + limit.next_yield = lua_async.clock() + limit.limit return true end -- cgit v1.2.3