# HG changeset patch # User Matthew Wild # Date 1521723720 0 # Node ID 1b7c5933b2151d304ba67fa424f5f0117d418697 # Parent 2f133b6e8740fab9f4f73cb94de38b2d4b3b643f util.async: Add sleep() method diff -r 2f133b6e8740 -r 1b7c5933b215 util/async.lua --- a/util/async.lua Thu Mar 22 11:56:03 2018 +0000 +++ b/util/async.lua Thu Mar 22 13:02:00 2018 +0000 @@ -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 @@ 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; };