Comparison

util/async.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 8976:92f0876b9230
child 9177:83e7ad5818d3
comparison
equal deleted inserted replaced
8994:f17e768c1a99 8995:2e6f7ab97794
1 local logger = require "util.logger"; 1 local logger = require "util.logger";
2 local log = logger.init("util.async"); 2 local log = logger.init("util.async");
3 local timer = require "util.timer";
3 local new_id = require "util.id".short; 4 local new_id = require "util.id".short;
4 5
5 local function checkthread() 6 local function checkthread()
6 local thread, main = coroutine.running(); 7 local thread, main = coroutine.running();
7 if not thread or main then 8 if not thread or main then
243 244
244 local function ready() 245 local function ready()
245 return pcall(checkthread); 246 return pcall(checkthread);
246 end 247 end
247 248
249 local function sleep(s)
250 local wait, done = waiter();
251 timer.add_task(s, done);
252 wait();
253 end
254
248 return { 255 return {
249 ready = ready; 256 ready = ready;
250 waiter = waiter; 257 waiter = waiter;
251 guarder = guarder; 258 guarder = guarder;
252 runner = runner; 259 runner = runner;
260 sleep = sleep;
253 }; 261 };