2014-04-27 23:55:49 +02:00
|
|
|
|
|
|
|
core.async_jobs = {}
|
|
|
|
|
|
|
|
local function handle_job(jobid, serialized_retval)
|
|
|
|
local retval = core.deserialize(serialized_retval)
|
|
|
|
assert(type(core.async_jobs[jobid]) == "function")
|
|
|
|
core.async_jobs[jobid](retval)
|
|
|
|
core.async_jobs[jobid] = nil
|
|
|
|
end
|
|
|
|
|
2020-05-15 16:38:19 +02:00
|
|
|
core.async_event_handler = handle_job
|
2014-04-27 23:55:49 +02:00
|
|
|
|
|
|
|
function core.handle_async(func, parameter, callback)
|
|
|
|
-- Serialize parameters
|
|
|
|
local serialized_param = core.serialize(parameter)
|
|
|
|
|
|
|
|
if serialized_param == nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2024-11-03 16:53:01 +01:00
|
|
|
local jobid = core.do_async_callback(func, serialized_param)
|
2014-04-27 23:55:49 +02:00
|
|
|
|
|
|
|
core.async_jobs[jobid] = callback
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|