There is such code:
Lua Code:
local EM = CreateFrame('Frame')
testTable = {}
for i = 1, 100000 do
testTable[i] = i
end
function DefPairs()
local startTime = GetTime()
for k, v in pairs(testTable) do
print(k)
end
print("LeadTime: " .. GetTime() - startTime)
end
function SmoothPairs(table, mult, callback)
EM:SetScript("OnUpdate", nil)
local prevFrameTime = 0
local startTime = GetTime()
local index, var = nil, nil
EM:SetScript("OnUpdate", function(self, elapsed)
if prevFrameTime == 0 then
prevFrameTime = GetTime()
else
local startFrameTime = GetTime()
local frameDeltaTime = startFrameTime - prevFrameTime
prevFrameTime = startFrameTime
local timeForWork = ( 0.0001 / frameDeltaTime ) * mult
local stopTaskTime = startFrameTime + timeForWork
while GetTime() < stopTaskTime do
index, var = next(table, index)
if not index then
EM:SetScript("OnUpdate", nil)
print("LeadTime: " .. GetTime() - startTime)
return
else
callback(index, var)
end
end
end
end)
end
function StopSmoothPairs()
EM:SetScript("OnUpdate", nil)
end
-- /run SmoothPairs(testTable, 1, function(k, v) print(k) end)
-- /run StopSmoothPairs()
-- /run DefPairs()
But it does not work as expected. Assault GetTime() returns always the same value inside the frame.
Later try to check using "anim:SetScript("OnLoop", ...)", he seems to have no such restrictions.