Comparison

util/timer.lua @ 8685:2548111e71d6

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
author Kim Alvefur <zash@zash.se>
date Fri, 23 Mar 2018 21:18:15 +0100
parent 8555:4f0f5b49bb03
child 8762:2f8523bf7ff2
comparison
equal deleted inserted replaced
8684:801f253ef52d 8685:2548111e71d6
8 8
9 local indexedbheap = require "util.indexedbheap"; 9 local indexedbheap = require "util.indexedbheap";
10 local log = require "util.logger".init("timer"); 10 local log = require "util.logger".init("timer");
11 local server = require "net.server"; 11 local server = require "net.server";
12 local get_time = require "util.time".now 12 local get_time = require "util.time".now
13 local async = require "util.async";
13 local type = type; 14 local type = type;
14 local debug_traceback = debug.traceback; 15 local debug_traceback = debug.traceback;
15 local tostring = tostring; 16 local tostring = tostring;
16 local xpcall = xpcall; 17 local xpcall = xpcall;
17 18
100 _add_task(next_time - current_time, _on_timer); 101 _add_task(next_time - current_time, _on_timer);
101 end 102 end
102 return id; 103 return id;
103 end 104 end
104 105
106 local function sleep(s)
107 local wait, done = async.waiter();
108 add_task(s, done);
109 wait();
110 end
111
105 return { 112 return {
106 add_task = add_task; 113 add_task = add_task;
107 stop = stop; 114 stop = stop;
108 reschedule = reschedule; 115 reschedule = reschedule;
116 sleep = sleep;
109 }; 117 };
110 118