aboutsummaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua21
1 files changed, 19 insertions, 2 deletions
diff --git a/util.lua b/util.lua
index 7061c06..dbef0b5 100644
--- a/util.lua
+++ b/util.lua
@@ -27,13 +27,30 @@ function lua_async.resume(co)
end
function lua_async.run()
- local last_time = os.clock()
+ assert(lua_async.socket)
+ local last_time = lua_async.clock()
while true do
- local current_time = os.clock()
+ local current_time = lua_async.clock()
local dtime = current_time - last_time
last_time = current_time
lua_async.step(dtime)
+
+ local next = math.huge
+
+ for _, timeout in pairs(lua_async.timeouts.pool)
+ next = math.min(next, timeout.time_left)
+ end
+
+ for _, interval in pairs(lua_async.intervals.pool)
+ next = math.min(next, interval.time_left)
+ end
+
+ if next == math.huge then
+ return
+ end
+
+ lua_async.socket.sleep(next)
end
end