--先上一个实例,再附源代码啦~
--日常使用本taskMaid的完整操作
taskMaid:onInit() --初始化任务管理器
--小任务:数苹果
--任务失败的回调函数
local function f_callback(n_delta)
print(n_delta)
end
--数一个苹果
local function f_task(t_cache)
t_cache[1]=t_cache[1]+1
return true --这条任务成功完成
end
local apple={0}
--注册一个任务
local order=taskMaid:requestNewTaskOrder("calculate_the_number_of_apples",f_callback,apple,1)
--为这个任务添加若干任务函数。在任务执行时,每一帧会执行一次任务
taskMaid:pushTask(order,f_task,1,"failed to calculate the number of apple!")
taskMaid:pushTask(order,function (t_cache)
t_cache[1]=t_cache[1]+5
return true
end,"failed to calculate the number of apple!")
--taskMaid:pushTask...
taskMaid:pushTask(order,function (t_cache)
chiefMaid:printLog("We have got %d apples!",t_cache[1])
end)
--开始启动这个任务
taskMaid:startTask(order)
--注意:taskMaid的任务并不是即时执行的,而是以一帧一步的方式执行的。在这一帧启动或终止任务,意为从下一帧开始执行或清理该任务。
while(tru
[LUA]taskMaid——多线程任务管理器(支持异步)
最新推荐文章于 2024-06-04 00:29:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)