diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-11-21 16:37:08 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-11-21 16:37:08 +0100 |
commit | 40beef755f0c47691b5cd5a79e76fdd361320aa8 (patch) | |
tree | 023dc702cab44be6b500dc0f1ef549090498e9b6 /limiting.lua | |
parent | d8c45339fcef6609dcc423480dcb70986237bf61 (diff) | |
download | lua_async-40beef755f0c47691b5cd5a79e76fdd361320aa8.tar.xz |
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
Diffstat (limited to 'limiting.lua')
-rw-r--r-- | limiting.lua | 6 |
1 files changed, 3 insertions, 3 deletions
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 |