修复TASK模块在协程报错后跳过删除task代码导致在错误界面连续爆炸
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
local rem=table.remove
|
local rem=table.remove
|
||||||
local ct=coroutine
|
|
||||||
local assert=assert
|
local assert=assert
|
||||||
|
local resume,status=coroutine.resume,coroutine.status
|
||||||
local tasks={}
|
local tasks={}
|
||||||
|
|
||||||
local TASK={}
|
local TASK={}
|
||||||
@@ -10,16 +10,17 @@ end
|
|||||||
function TASK.update()
|
function TASK.update()
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
local T=tasks[i]
|
local T=tasks[i]
|
||||||
assert(ct.resume(T.thread))
|
if status(T.thread)=="dead"then
|
||||||
if ct.status(T.thread)=="dead"then
|
rem(tasks,i)
|
||||||
rem(tasks,i)
|
else
|
||||||
|
assert(resume(T.thread))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function TASK.new(code,...)
|
function TASK.new(code,...)
|
||||||
local thread=ct.create(code)
|
local thread=coroutine.create(code)
|
||||||
ct.resume(thread,...)
|
resume(thread,...)
|
||||||
if ct.status(thread)~="dead"then
|
if status(thread)~="dead"then
|
||||||
tasks[#tasks+1]={
|
tasks[#tasks+1]={
|
||||||
thread=thread,
|
thread=thread,
|
||||||
code=code,
|
code=code,
|
||||||
|
|||||||
Reference in New Issue
Block a user