Thread Tools Display Modes
11/03/21, 09:36 AM   #1
Psiioniic
AddOn Author - Click to view addons
Join Date: Aug 2018
Posts: 18
Async computation question

Hi,

I'm not experienced in async computations in lua, so sorry for my probably stupid questions.

I want to run a computation which depending on the case might take considerable amount of time, maybe hundreds of ms or even a second, but I don't want the game/ui to freeze or lag during this time.

I found this thread from 2018 recommending libAsync
https://www.esoui.com/forums/showthread.php?t=7891

So do I understand correctly that I have to partition my task in multiple steps, making each step so small that it fits in a single frame (even on a low end machine) and then use
function task:For(from, to, step): Do(someFunction)
from libAsync?

Are there any other alternatives? e.g. ones which work more like threads, (to allow having the loop inside the user function)?
  Reply With Quote
11/03/21, 09:48 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
https://wiki.esoui.com/Running_LUA-Code_asynchroneously

Having a loop inside a function is not async but sync and will lag the client if the loop takes too long.
A few ms or 1 second is no problem except if this repeats every 1 second again
Like scanning all items of the game will lag the client, so one needs to break it up into portions and scan only 1 portion after another.
Sou you manually do a fragmentation of the whole pile to scan, create packages and scan each package after the next. Each package contains only like 200 itemIds and thus it won't lag the client that much (depends on the user's hardware though).

But depending on the total amount of ids/stuff to scan, and what you are doing with it afterwards (calling API functions to get their level, quality, if it is a set, ...) it will become lagging.
This is why sort of that info is done only once after a patch/APIVersion increase and cached to the SavedVariables.
Often libraries will do that so an addon only needs to use that lib and all benefit from it.

If you tell us what you want to do, maybe here in the dev chat, we would be able to help better.

Last edited by Baertram : 11/03/21 at 09:54 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Async computation question

Thread Tools
Display Modes

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