diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-03-22 07:56:01 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-03-22 07:56:01 +0000 |
commit | c600e0f6f60245d4c5ed9287fb5f2ccbdf06d8f1 (patch) | |
tree | 4f94912e6ab5403a1322045f6b9e55d5b59404dc /util/async.lua | |
parent | 430eef84208c1e4a0d07a2b32d76dccea731ca13 (diff) | |
download | prosody-c600e0f6f60245d4c5ed9287fb5f2ccbdf06d8f1.tar.gz prosody-c600e0f6f60245d4c5ed9287fb5f2ccbdf06d8f1.zip |
util.async: Add once() to create temporary runners
Diffstat (limited to 'util/async.lua')
-rw-r--r-- | util/async.lua | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/util/async.lua b/util/async.lua index 1930d1a9..8e75a524 100644 --- a/util/async.lua +++ b/util/async.lua @@ -219,4 +219,24 @@ local function ready() return pcall(checkthread); end -return { ready = ready, waiter = waiter, guarder = guarder, runner = runner }; +local once; -- forward declaration +do + local once_watchers = { + error = function (_, err) + error(err); + end; + }; + local function once_runner(func) func(); end + function once(func) + local r = runner(func, once_watchers); + return r:run(func); + end +end + +return { + once = once; + ready = ready; + waiter = waiter; + guarder = guarder; + runner = runner +}; |