]> git.lizzy.rs Git - lua_async.git/blob - init.lua
Implement poll phase
[lua_async.git] / init.lua
1 lua_async = {
2         poll_functions = {},
3 }
4
5 if rawget(_G, "require") then
6         lua_async.socket = require("socket")
7 end
8
9 function lua_async.clock()
10         return lua_async.socket and lua_async.socket.gettime() or os.clock()
11 end
12
13 function lua_async.step(dtime)
14         -- timers phase
15         lua_async.timeouts.step(dtime)
16         lua_async.intervals.step(dtime)
17
18         -- pending callbacks phase is obsolete
19
20         -- idle & prepare phase are obsolete
21
22         -- poll phase
23         for func in pairs(lua_async.poll_functions) do
24                 func()
25         end
26
27         -- check phase
28         lua_async.immediates.step(dtime)
29
30         -- close phase is obsolete
31 end
32
33 return function(path)
34         for _, f in ipairs {
35                 "timeouts",
36                 "intervals",
37                 "immediates",
38                 "promises",
39                 "async_await",
40                 "util",
41                 "limiting",
42                 "events",
43         } do
44                 dofile(path .. f .. ".lua")
45         end
46 end