util.timer: Move sleep() here from util.async

This is to solve a indirect dependency issue where net.server was initialized before the config was read
This commit is contained in:
Kim Alvefur 2018-03-23 21:18:15 +01:00
parent 57f5ea520f
commit 2fa049d2e1
2 changed files with 8 additions and 8 deletions

View file

@ -1,6 +1,5 @@
local log = require "util.logger".init("util.async"); local log = require "util.logger".init("util.async");
local new_id = require "util.id".short; local new_id = require "util.id".short;
local timer = require "util.timer";
local function checkthread() local function checkthread()
local thread, main = coroutine.running(); local thread, main = coroutine.running();
@ -226,16 +225,9 @@ local function ready()
return pcall(checkthread); return pcall(checkthread);
end end
local function sleep(s)
local wait, done = waiter();
timer.add_task(s, done);
wait();
end
return { return {
ready = ready; ready = ready;
waiter = waiter; waiter = waiter;
guarder = guarder; guarder = guarder;
runner = runner; runner = runner;
sleep = sleep;
}; };

View file

@ -10,6 +10,7 @@ local indexedbheap = require "util.indexedbheap";
local log = require "util.logger".init("timer"); local log = require "util.logger".init("timer");
local server = require "net.server"; local server = require "net.server";
local get_time = require "util.time".now local get_time = require "util.time".now
local async = require "util.async";
local type = type; local type = type;
local debug_traceback = debug.traceback; local debug_traceback = debug.traceback;
local tostring = tostring; local tostring = tostring;
@ -102,9 +103,16 @@ local function reschedule(id, delay)
return id; return id;
end end
local function sleep(s)
local wait, done = async.waiter();
add_task(s, done);
wait();
end
return { return {
add_task = add_task; add_task = add_task;
stop = stop; stop = stop;
reschedule = reschedule; reschedule = reschedule;
sleep = sleep;
}; };