# HG changeset patch # User Kim Alvefur # Date 1521836295 -3600 # Node ID 2548111e71d668d7036ab822ebad2ffb682245b8 # Parent 801f253ef52dfb01a96caafc23daa7724fdb338c 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 diff -r 801f253ef52d -r 2548111e71d6 util/async.lua --- a/util/async.lua Fri Mar 23 20:57:34 2018 +0100 +++ b/util/async.lua Fri Mar 23 21:18:15 2018 +0100 @@ -1,6 +1,5 @@ local log = require "util.logger".init("util.async"); local new_id = require "util.id".short; -local timer = require "util.timer"; local function checkthread() local thread, main = coroutine.running(); @@ -226,16 +225,9 @@ return pcall(checkthread); end -local function sleep(s) - local wait, done = waiter(); - timer.add_task(s, done); - wait(); -end - return { ready = ready; waiter = waiter; guarder = guarder; runner = runner; - sleep = sleep; }; diff -r 801f253ef52d -r 2548111e71d6 util/timer.lua --- a/util/timer.lua Fri Mar 23 20:57:34 2018 +0100 +++ b/util/timer.lua Fri Mar 23 21:18:15 2018 +0100 @@ -10,6 +10,7 @@ local log = require "util.logger".init("timer"); local server = require "net.server"; local get_time = require "util.time".now +local async = require "util.async"; local type = type; local debug_traceback = debug.traceback; local tostring = tostring; @@ -102,9 +103,16 @@ return id; end +local function sleep(s) + local wait, done = async.waiter(); + add_task(s, done); + wait(); +end + return { add_task = add_task; stop = stop; reschedule = reschedule; + sleep = sleep; };