|
-
- local FunctionQueue = class("FunctionQueue")
-
- --[[
- 执行队列
- ]]--
-
- function FunctionQueue:ctor()
- self.FunctionQueue = {};
- self.isRunning = false;
- end
-
- function FunctionQueue:clear()
- self.FunctionQueue = {}
- self.isRunning = false;
- end
-
- function FunctionQueue:addFunction(func)
-
- -- 添加到执行队列
- table.insert(self.FunctionQueue, func)
-
- local function runFunc()
- if #self.FunctionQueue <= 0 then
- self.isRunning = false
- return
- end
-
- local fun = self.FunctionQueue[1]
- table.remove(self.FunctionQueue,1)
- self.isRunning = true
-
- fun(function()
- self.isRunning = false;
- runFunc();
- end)
- end
-
- -- 如果当前没有在执行,则马上开始执行
- log("self.isRunning:", self.isRunning)
-
- if not self.isRunning then
- runFunc();
- end
- end
-
- return FunctionQueue
|