async.lua 585 B

12345678910111213141516171819202122
  1. core.async_jobs = {}
  2. function core.async_event_handler(jobid, retval)
  3. local callback = core.async_jobs[jobid]
  4. assert(type(callback) == "function")
  5. callback(unpack(retval, 1, retval.n))
  6. core.async_jobs[jobid] = nil
  7. end
  8. function core.handle_async(func, callback, ...)
  9. assert(type(func) == "function" and type(callback) == "function",
  10. "Invalid core.handle_async invocation")
  11. local args = {n = select("#", ...), ...}
  12. local mod_origin = core.get_last_run_mod()
  13. local jobid = core.do_async_callback(func, args, mod_origin)
  14. core.async_jobs[jobid] = callback
  15. return true
  16. end