Wait For
Pre-releaseThis draft contains a new wait for %Executable%
effect. This is not to be confused with the existing wait %Duration%
effect.
The wait for ...
effect is designed for creating advanced multi-process code.
It runs an executable on a background thread but waits for its completion, preserving the execution order.
wait for a new runnable:
print "1"
wait 1 second
print "2"
print "3"
This behaviour is semi-equivalent to a regular run
.
run a new runnable:
print "1"
wait 1 second
print "2"
print "3"
The key difference between these two is that the background process can be branched off by cancelling the wait with a wake
effect.
set {thread} to the current thread
wait for a new runnable:
print "1"
wake {thread} // the wait ends here
wait 1 second
print "3"
print "2"
This is a lot safer than using sleep/wake with a regular run ... in the background
since a hidden monitor preserves the happens-before relationship and makes sure the code executes in the expected order.
This draft also covers a minor inconsistency that recycled background processes could keep the thread variables that were previously set.