Re: Threads and Concurrency Question
wikner wrote:So suppose Script 1 activates on a timer and changes Variable 1, then changes Variable 2, then does some other processing before it exits. Script 2 activates on the change in Variable 1, and Script 3 activates on the change in Variable 2.
Embedded AppleScripts and functions defined in attachment scripts execute in the main Indigo Server thread. Linked AppleScripts execute in their own process. Variable changes cause dependent Trigger Actions to occur immediately after the variable has changed.
So if you have an Attachment script function (or an embedded script) that changes variable foo1 and then variable foo2, and you have a Trigger Action on foo1 and foo2 that execute embedded script actions, then the order will be:
attachment script function (or embedded script)
change of variable foo1
foo1 Trigger Action script execute starts
foo1 Trigger Action script finishes
change of variable foo2
foo2 Trigger Action script execute starts
foo2 Trigger Action script finishes
If the Trigger Actions for variable foo1 and foo2 are linked (not embedded), then they Indigo Server will start a new process to execute the scripts. The order will then be indeterminate. The order will also be indeterminate if your original script is not embedded or isn't all defined inside a single attachment script function (foo2 may get modified before the foo1 Trigger Action script is finished executing).