diff options
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 +}; |