Comparison

util/timer.lua @ 8995:2e6f7ab97794

util.{async,timer}: Move sleep() to reduce dependencies of util.timer
author Kim Alvefur <zash@zash.se>
date Sun, 08 Jul 2018 00:37:01 +0200
parent 8762:2f8523bf7ff2
child 9562:acf74ad0b795
comparison
equal deleted inserted replaced
8994:f17e768c1a99 8995:2e6f7ab97794
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";
14 local type = type; 13 local type = type;
15 local debug_traceback = debug.traceback; 14 local debug_traceback = debug.traceback;
16 local tostring = tostring; 15 local tostring = tostring;
17 local xpcall = xpcall; 16 local xpcall = xpcall;
18 local math_max = math.max; 17 local math_max = math.max;
102 _add_task(next_time - current_time, _on_timer); 101 _add_task(next_time - current_time, _on_timer);
103 end 102 end
104 return id; 103 return id;
105 end 104 end
106 105
107 local function sleep(s)
108 local wait, done = async.waiter();
109 add_task(s, done);
110 wait();
111 end
112
113 return { 106 return {
114 add_task = add_task; 107 add_task = add_task;
115 stop = stop; 108 stop = stop;
116 reschedule = reschedule; 109 reschedule = reschedule;
117 sleep = sleep;
118 }; 110 };
119 111