You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
807 B

  1. local FunctionQueue = class("FunctionQueue")
  2. --[[
  3. 执行队列
  4. ]]--
  5. function FunctionQueue:ctor()
  6. self.FunctionQueue = {};
  7. self.isRunning = false;
  8. end
  9. function FunctionQueue:clear()
  10. self.FunctionQueue = {}
  11. self.isRunning = false;
  12. end
  13. function FunctionQueue:addFunction(func)
  14. -- 添加到执行队列
  15. table.insert(self.FunctionQueue, func)
  16. local function runFunc()
  17. if #self.FunctionQueue <= 0 then
  18. self.isRunning = false
  19. return
  20. end
  21. local fun = self.FunctionQueue[1]
  22. table.remove(self.FunctionQueue,1)
  23. self.isRunning = true
  24. fun(function()
  25. self.isRunning = false;
  26. runFunc();
  27. end)
  28. end
  29. -- 如果当前没有在执行,则马上开始执行
  30. log("self.isRunning:", self.isRunning)
  31. if not self.isRunning then
  32. runFunc();
  33. end
  34. end
  35. return FunctionQueue