Software /
code /
prosody
Diff
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 |
line wrap: on
line diff
--- a/util/async.lua Sat Jul 07 21:55:18 2018 +0200 +++ b/util/async.lua Sun Jul 08 00:37:01 2018 +0200 @@ -1,5 +1,6 @@ local logger = require "util.logger"; local log = logger.init("util.async"); +local timer = require "util.timer"; local new_id = require "util.id".short; local function checkthread() @@ -245,9 +246,16 @@ return pcall(checkthread); end +local function sleep(s) + local wait, done = waiter(); + timer.add_task(s, done); + wait(); +end + return { ready = ready; waiter = waiter; guarder = guarder; runner = runner; + sleep = sleep; };