I’m running version 4.7.
I have some code in the “On Variation” callback in my global rackspace script which calls GetRackspaceNameAtIndex(GetCurrentRackspaceIndex()).
I’ve noticed that when I first run the application and load my gigfile, this callback gets called many times: once for most of the rackspaces in the gigfile (but not all). I’m curious as to why it isn’t called for every rackspace.
I’ve also noticed that on some occasions (which I can’t reliably replicate), GetCurrentRackspaceIndex() returns -1 (which is accompanied by the error “GetRackspaceNameAtIndex() canot be called at this time”), and sometimes when it returns 0, which is a valid rackspace index, GetRackspaceNameAtIndex nevertheless returns an empty string and emits the same error message.
Now, none of my “On Variation” code actually needs to be run at gig load. I only need this code to execute when the user is actually switching to a variation for performance. So I have two pressing questions:
-
In order to speed up the loading of my gig file, is there a way that I can detect that a given “On Variation” call is happening during load (in which case it can immediately return without doing any work) versus during ordinary operation (in which case it needs to do what I’ve designed it to do?)
-
I’m supposing that the sporadic errors are happening because the “On Variation” is invoked in one thread, whereas the rackspace state that GetCurrentRackspaceIndex and GetRackspaceNameAtIndex are relying on is being set up in a different thread. How can I reliably know that the new rackspace/variation has been fully loaded before I proceed? My current best idea is to loop until GetCurrentRackspaceIndex() returns a nonnegative integer, and then loop until GetCurrentRackspaceIndex() returns a nonempty string. However, I’m not certain that even this would guarantee that I can safely proceed, and I’m a bit nervous about the possibility of infinite loops.