Hi Chris,
It looks like there’s an issue where wait_for_condition() sometimes throws a ‘cannot execute outside of the main state system’ error. I’ve attached a testcase and a screenshot of the console error.
I’m not sure what’s going on. Can you look into this?
thanks,
Mark
Hi Chris,
Small update. I was able to work around this particular issue with a while() { } block, manually spinning. So it’s no longer super-urgent, but it would be nice to know what I did wrong here in the next few days.
thanks,
Mark
Hi Mark,
You didn’t do anything wrong. I was being a bit lazy when I implemented wait_for_condition and didn’t want to support executing it inside a scheduled actions instance (which is the primary way an experiment can perform actions outside of the main state system). However, it didn’t occur to me that this would also cause it to fail inside if
and while
(which are themselves implemented in a sort of lazy way that makes it appear to contained actions that they aren’t running on the main state system). I will fix this.
In the meantime, using a while
loop is a good workaround, though I recommend including a short wait (e.g. 500us) in the loop body, so that you aren’t burning up CPU cycles unnecessarily. If you need it in a bunch of places, you can create a macro for it.
Cheers,
Chris
Hi Chris,
Great, thanks for working on it.
Re: the workaround, yes, that’s exactly what I did — added a holdoff each time through the loop. And I did set that time to 0.5ms as you suggested. We’re on the same page.
thanks!
Mark
Hi Mark,
This is fixed. As of the current nightly build, wait_for_condition can be used anywhere actions are allowed (including if, while, and scheduled actions).
Cheers,
Chris