This commit is contained in:
aixianling
2024-12-13 13:41:02 +08:00
commit 06658f112f
3887 changed files with 2687822 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
module("AsyncWorkDispatcher", package.seeall)
local CallBackList = {}
-- @brief 添加异步工作
-- @param asyncWork 异步工作内容 => { 'function', arg1, arg2 ... }
-- @param callback 完成回调 格式: callback(paramPack,retParam...) => paramPack为传入参数包retParam为异步工作返回值
-- @param paramPack 回调参数包
-- @note asyncWork.function 在异步线程中调用,且应函数应定义在 AsyncWorkerFunction.txt
function Add(asyncWork,callback,paramPack)
local cbid = System.addAsyncWorker(asyncWork)
if cbid ~= nil and cbid ~= 0 and callback ~= nil then
CallBackList[cbid] = {callback, paramPack}
end
end
--------------------------------------------------------------------
-- 提供给CPP的回调
--------------------------------------------------------------------
function OnWorkFinish(cbid, empty, ...)
if not cbid then return end
local callback = CallBackList[cbid]
if callback ~= nil then
func = callback[1]
paramPack = callback[2]
func(paramPack, ...)
CallBackList[cbid] = nil
end
end