ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Async computation question (https://www.esoui.com/forums/showthread.php?t=9972)

Psiioniic 11/03/21 09:36 AM

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
Quote:

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)?

Baertram 11/03/21 09:48 AM

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.


All times are GMT -6. The time now is 11:24 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI