mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 21:57:45 +03:00
util.{async,timer}: Move sleep() to reduce dependencies of util.timer
This commit is contained in:
parent
b58c44e43a
commit
9c48fc4726
2 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue