So, "repeat" holds up system resources (even with "wait 500 milliseconds with messages"), but
"send in 500 milliseconds" doesn't.
Not exactly, it depends on balance. For example, this will lock up everything until the loop is finished:
Code: Select all
repeat with x = 1 to someHugeNumber
add 1 to x
end repeat
If a loop is going to run a long time, you should yield time to the OS and other processes:
Code: Select all
repeat with x = 1 to someHugeNumber
add 1 to x
wait 1 with messages
end repeat
This will slow down the handler because there's a wait inserted, but it plays nice with other processes. The loop itself is very short and will run very fast (it only has one operation to do.) The balance between the loop activity and background processes is sort of equal. If the wait were extended to 500 milliseconds, the loop would yield more time than it takes to do its processing. The handler would be slow and inefficient. And if any other event happens during the loop (like a mouseclick) that doesn't occur exactly during the "wait" statement, that event will either be missed or postponed. The engine will only check for user and system events during the wait. A short loop like this one with half the time dedicated to a "wait" will probably catch most events, but may not catch all.
If the loop takes a long time to execute and the wait is short, the balance changes:
Code: Select all
repeat with x = 1 to someHugeNumber
doSomethingReallyTimeConsuming
wait 1 with messages
doMoreTimeConsumingStuff
end repeat
In this case the handler blocks everything while the loop runs and yields only a tiny sliver to the OS. Background processes will slow down or stop and LiveCode will use almost all the CPU. Most user events will be missed or postponed because it's unlikely they will occur during the precise moment when the wait is happening. Yielding a tiny slice is better than not yielding at all, but the balance is off. Sometimes you have no choice, but when possible it's better to avoid this.
If a script needs to do only occasional polling, like checking a timer, then pulling it out of the repeat loop entirely is a better way to go. Instead of relying on a "wait" to catch events, the script instead allows unlimited events in between calls to the timer-checking handler. Basically the balance is reversed -- more time is spent with no handlers running at all (freeing up all system resources,) and only momentary checks are done on a schedule.
That may be more than you wanted to know.
