From f90a032fb690903079e1dde5dc414c994fc6f2b2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 22 Mar 2018 13:02:00 +0000 Subject: util.async: Add sleep() method --- util/async.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/async.lua b/util/async.lua index 8e75a524..7a8bd686 100644 --- a/util/async.lua +++ b/util/async.lua @@ -1,5 +1,6 @@ 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(); @@ -233,10 +234,17 @@ do end end +local function sleep(s) + local wait, done = waiter(); + timer.add_task(s, done); + wait(); +end + return { once = once; ready = ready; waiter = waiter; guarder = guarder; - runner = runner + runner = runner; + sleep = sleep; }; -- cgit v1.2.3