Comparison

util/async.lua @ 8649:9246f64d6f1e

util.async: Add once() to create temporary runners
author Matthew Wild <mwild1@gmail.com>
date Thu, 22 Mar 2018 07:56:01 +0000
parent 8648:ca710a71d730
child 8651:1b7c5933b215
comparison
equal deleted inserted replaced
8648:ca710a71d730 8649:9246f64d6f1e
217 217
218 local function ready() 218 local function ready()
219 return pcall(checkthread); 219 return pcall(checkthread);
220 end 220 end
221 221
222 return { ready = ready, waiter = waiter, guarder = guarder, runner = runner }; 222 local once; -- forward declaration
223 do
224 local once_watchers = {
225 error = function (_, err)
226 error(err);
227 end;
228 };
229 local function once_runner(func) func(); end
230 function once(func)
231 local r = runner(func, once_watchers);
232 return r:run(func);
233 end
234 end
235
236 return {
237 once = once;
238 ready = ready;
239 waiter = waiter;
240 guarder = guarder;
241 runner = runner
242 };