瀏覽代碼

Preserve ordering in CooperativeScheduler;

bjorn 8 年之前
父節點
當前提交
449e29b31c
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. 5 1
      rx.lua
  2. 5 1
      src/schedulers/cooperativescheduler.lua

+ 5 - 1
rx.lua

@@ -1865,7 +1865,8 @@ end
 function CooperativeScheduler:update(delta)
   self.currentTime = self.currentTime + (delta or 0)
 
-  for i = #self.tasks, 1, -1 do
+  local i = 1
+  while i <= #self.tasks do
     local task = self.tasks[i]
 
     if self.currentTime >= task.due then
@@ -1875,11 +1876,14 @@ function CooperativeScheduler:update(delta)
         table.remove(self.tasks, i)
       else
         task.due = math.max(task.due + (delay or 0), self.currentTime)
+        i = i + 1
       end
 
       if not success then
         error(delay)
       end
+    else
+      i = i + 1
     end
   end
 end

+ 5 - 1
src/schedulers/cooperativescheduler.lua

@@ -56,7 +56,8 @@ end
 function CooperativeScheduler:update(delta)
   self.currentTime = self.currentTime + (delta or 0)
 
-  for i = #self.tasks, 1, -1 do
+  local i = 1
+  while i <= #self.tasks do
     local task = self.tasks[i]
 
     if self.currentTime >= task.due then
@@ -66,11 +67,14 @@ function CooperativeScheduler:update(delta)
         table.remove(self.tasks, i)
       else
         task.due = math.max(task.due + (delay or 0), self.currentTime)
+        i = i + 1
       end
 
       if not success then
         error(delay)
       end
+    else
+      i = i + 1
     end
   end
 end