|
_gUdefCoroutinePool = {} -- 自定义线程池
-- 自定义唤醒事件
function udefDispatchEvent(event, ...)
local parameterList = { ... }
local co = coroutine.create(function()
while true do
coroutine.yield(event, parameterList)
end
end)
table.insert(_gUdefCoroutinePool, { ["co"] = co, ["ev"] = event })
end
-- 自定义注册事件
function udefRegisterEvent(event, func)
for _, v in pairs(_gUdefCoroutinePool) do
local bool, _event, parameterList = coroutine.resume(v.co)
if event == _event then
func(unpack(parameterList))
return v
end
end
end
-- 取消唤醒事件
function removeUdefDispatchEvent(event)
for k, v in pairs(_gUdefCoroutinePool) do
if event == v.ev then
table.remove(-_gUdefCoroutinePool, k)
break
end
end
end
|
|