File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,12 +77,15 @@ local tasks={}
7777--- Update all tasks (called by Zenitha)
7878--- @param dt number
7979function TASK ._update (dt )
80- for i =# tasks ,1 ,- 1 do
80+ local i ,n = 1 ,# tasks
81+ while i <= n do
8182 local T = tasks [i ]
82- if status (T .thread )== ' dead' then
83+ if not T or status (T .thread )== ' dead' then
8384 rem (tasks ,i )
85+ n = n - 1
8486 else
8587 assert (resume (T .thread ,dt ))
88+ i = i + 1
8689 end
8790 end
8891end
@@ -104,7 +107,8 @@ function TASK.new(code,...)
104107 end
105108end
106109
107- --- Get the number of tasks
110+ --- Get the number of tasks
111+ --- Warning: the result is not accurate during TASK._update, tasks removed during the update still count
108112--- @return number
109113function TASK .getCount ()
110114 return # tasks
113117--- Remove task(s) by specified code(the function which created the task)
114118--- @param code function
115119function TASK .removeTask_code (code )
116- for i =# tasks , 1 , - 1 do
117- if tasks [i ].code == code then
118- rem ( tasks , i )
120+ for i = 1 , # tasks do
121+ if tasks [i ] and tasks [ i ] .code == code then
122+ tasks [ i ] = false
119123 end
120124 end
121125end
124128--- @param func function
125129--- @param ... any Arguments passed to the given function
126130function TASK .removeTask_iterate (func ,...)
127- for i =# tasks , 1 , - 1 do
128- if func (tasks [i ],... ) then
129- rem ( tasks , i )
131+ for i = 1 , # tasks do
132+ if tasks [ i ] and func (tasks [i ],... ) then
133+ tasks [ i ] = false
130134 end
131135 end
132136end
You can’t perform that action at this time.
0 commit comments