2
0

async_event.lua 588 B

123456789101112131415161718192021222324252627
  1. core.async_jobs = {}
  2. local function handle_job(jobid, serialized_retval)
  3. local retval = core.deserialize(serialized_retval)
  4. assert(type(core.async_jobs[jobid]) == "function")
  5. core.async_jobs[jobid](retval)
  6. core.async_jobs[jobid] = nil
  7. end
  8. core.async_event_handler = handle_job
  9. function core.handle_async(func, parameter, callback)
  10. -- Serialize parameters
  11. local serialized_param = core.serialize(parameter)
  12. if serialized_param == nil then
  13. return false
  14. end
  15. local jobid = core.do_async_callback(func, serialized_param)
  16. core.async_jobs[jobid] = callback
  17. return true
  18. end