Variable Scope

Anything is possible, since unfortunately neither of us can read the internal implementation of state to understand how it might behave in various situations. :wink:

You could also try experimenting with this setting to see if it makes any difference for better or worse: [2.2.9] singleThreaded option for apps/drivers

It was my impression in the past that state is only sampled once at the "top" of a method call and isn't updated continuously throughout, so maybe you're seeing something of that sort. It would be interesting to see if the singleThreaded setting makes any difference. If not, you may have to refactor your method to make individual method calls to do the checking while you're waiting so that you get an updated sample of state. This may be as simple as creating a sub-function to check state instead of doing it directly in the calling method.