View Single Post
09/07/14, 02:51 AM   #1
Klingo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
Wait for a function to end before continue

Hi

I have a function that is triggered by an event and within this function there are several sub-functions that are called.
The first sub-functions makes use of some "zo_callLater" and the end of this sub-function is reached earlier than all the "zo_callLater" are ended (they might take 2-3 seconds). So the second sub-function is already called although not all "zo_callLater" from the first sub-function have ended, which causes some problems in the addon.

Currently I deal with this situation in the following way:
The first sub-function returns "true" as soon as all "zo_callLater" calls are completed. I then check this value in a loop if it is "true" and only in that case allow the main function to call the second sub-function.
Lua Code:
  1. local mainFunction()
  2.     -- call the first sub-function that contains some 'zo_callLater'
  3.     local isCompleted = callFirstSubFunction()
  4.  
  5.     while (isCompleted == nil) do
  6.         -- do nothing; wait
  7.     end
  8.  
  9.     -- call the second sub-function
  10.     callAnotherSubFunction()
  11. end

It basically works, but I am not sure how bad (performance-wise) this solution is.
I don't see any game-freezing effects like a regular endless-loop would cause, but I thought there might be a better solution for this?

Klingo
  Reply With Quote