Script Execution Delays
-
I am trying to execute a set of automation rules a set amount of time after a boolean flag becomes true. I don't want to use a chron and would like for it to be event driven. I don't want to stop evaluation of the rest of the script - I just want to look at the difference in time from one event and if it exceeds a preset, perform a subsequent action. I have tried to write a sleep function and setTimeout - neither of which are working. Is there a better way to do this?
Pseudocode is as follows:
If startTimer = True and it has been 10s since startTimer has been set to True, set startRules = true.
Note: I currently have startTimer enabled to udate context.
-
Hi bkeppel, welcome to the forum!
I have tried to write a sleep function
The JavaScript environment in Mango provide a sleep function,
RuntimeManager.sleep(milliseconds)
Pseudocode is as follows:
If startTimer = True and it has been 10s since startTimer has been set to True, set startRules = true.
Note: I currently have startTimer enabled to udate context.It sounds to me like what you want is to put a "State" event detector on the startTimer point, having a 10 second duration (to ensure it's been in the start timer state for 10 seconds), and then create an event handler to do the control that you would like to do after the event becomes active (eliminating the need to sleep in the script).
You should do what makes sense to you though, if knowing about the existing sleep function is enough to achieve what you're working on.