Even from Java code, you should basically never call wait()
or notify()
. I would definitely not do it from scripting.
I strongly suspect the only real way out here is rearchitecting; perhaps message handlers reacting to each 'stage' in this process accordingly. There's no way to do 'blocking' work like this in scripting.