I'm not sure I fully understand your design, what exactly are you trying to do and why... but:
As Steve suggested, the best way to do something like this would be taking care of the delay during a WebRFC. The WebRFC could check whether the order in question is still locked and wait until it has been released, then give control back to your script in the flavor.