Software /
code /
prosody
Diff
util/async.lua @ 8651:1b7c5933b215
util.async: Add sleep() method
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Mar 2018 13:02:00 +0000 |
parent | 8649:9246f64d6f1e |
child | 8655:ba6a6a04b46c |
line wrap: on
line diff
--- 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; };