util.{async,timer}: Move sleep() to reduce dependencies of util.timer

This commit is contained in:
Kim Alvefur 2018-07-08 00:37:01 +02:00
parent b58c44e43a
commit 9c48fc4726
2 changed files with 8 additions and 8 deletions

View file

@ -1,5 +1,6 @@
local logger = require "util.logger"; local logger = require "util.logger";
local log = logger.init("util.async"); local log = logger.init("util.async");
local timer = require "util.timer";
local new_id = require "util.id".short; local new_id = require "util.id".short;
local function checkthread() local function checkthread()
@ -245,9 +246,16 @@ 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,7 +10,6 @@ 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;
@ -104,16 +103,9 @@ 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;
}; };