View Single Post
06/24/18, 05:43 AM   #2
Shinni
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 167
Lua does have them, but the lua variant used in eso is stripped of coroutines.

Votan created a lib (LibAsync), which can be used instead. With the lib you can create a sequence of commands which are then spread over multiple frames via the game's OnUpdate event.

You can find the lib in his minimap addon. I haven't used the lib myself so the following example might be wrong. From looking at the lib's code I think it is used like this:

Let's say you want to replace the following:
Lua Code:
  1. for i = startValue, endValue do
  2.     something with value i
  3. end
then you can instead do
Lua Code:
  1. local async = LibStub("LibAsync")
  2.  
  3. local someFunction = function( i )
  4.     something with value i
  5. end
  6. --variant A
  7. local task = async:Create("yourTaskName")
  8. task:For(startValue, endValue):Do(someFunction)
  9. -- OR variant B
  10. async:For(startValue, endValue):Do(someFunction)

Variant A has the benefit that you can pause or interrupt the task via task:Suspend() or task:Cancel()

Last edited by Shinni : 06/24/18 at 05:50 AM.
  Reply With Quote