Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-04-21, 04:19 AM   #1
maqjav
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Feb 2012
Posts: 60
Pattern to manage heavy operations

Hello.

I'm planning on writing a piece of code that will process a lot of information and I'm afraid that this will freeze the users client. How can I avoid this situation?

Let's put it in an example:

Code:
local chunkSize = 100

function getNextChunk(currentPosition)
     -- return next chunk from huge table.
end

function processItem(data)
    -- Data is also a big table that will require several operations
end

function doIt(currentPosition, callback) 
    local nextChunk = getNextChunk(currentposition)
    if (not nextChunk) then
         return
    end

    local currentIndex = -1
    for id, data in pairs (nextChunk) do
        currentIndex = currentIndex + 1

        -- continue next chunk
        if (currentIndex ~= chunkSize) then
             callback(processItem(data))
        else
             -- process next chunk after sometime, using an async timer or OnUpdate?
             -- this is the part I'm missing
             return
        end
    end
end
Or perhaps instead of processing the table by chunks use a ticker or something like that and process 1 by 1?

Thanks!

Last edited by maqjav : 09-04-21 at 04:21 AM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Pattern to manage heavy operations


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off