Javascript – JScript Wait function

javascriptsuspendwaitwsh

I have a function written in JScript (Not javascript) I need to suspend until a certain global variable becomes true.
The global variable is changed to true when another function is called after an ajax response:

function(req, event, data) {
        globalVariable = true;
    } 

When I try to loop until the variable is true:

while (globalVariable!= true) {
}

I go into a busy waiting and the callback function is never called.

Some suggested the use of WScript.wait() but my app doesn't seam to know WScript.
SetTimeout() also won't help because it's asynchronic call and won't suspend my original function.

Any other suggestion?

Some more information regarding my question:
I want my script to call 2 functions:

waitWhileAjaxIsNotCompleted();
doSomthingElse();

I want the waitWhileAjaxIsNotCompleted() to click a button that submits an ajax request (implemented by A4J) and terminate upon the ajax completion.
In order for me to know when does tha ajax completed, I registered a function as a listener that will be awaken when the ajax completes. This function changes a globalVariable value.
My waitWhileAjaxIsNotComplete() goes into an infinite loop, waiting for the glovalVariable value to change. When it does change (After the listener has awaken), I can end the function ad continue with the doSomthingElse() function.

You can see more on the implementation on: QTP Web extensibilty toolkit and ajax

Best Answer

I can't remember what the heck I used a few months ago since I don't use Jscript anymore (not enough time)... But I am currently looking in my program to see if I still have the script saved. I did the exact same thing a few months back.

I'll post the code once I've found it...


Sorry about that. I can't seem to find the code snippet. I must have deleted it... Typical of me though.

So, the only thing that I can think of until a better solution is available it to enter your code into an infinite loop, and simply break; out of it once the GlobalVariable returns true.

I hope this helps. I'm going to keep at it until I can either find the snippet or come up with a much better answer.