sachitjain
asked on
How to implement synchronous pause with JScript?
I want to implement synchronous pause with JScript. Unfortunately there is no delay or pause or wait function in JScript library to support this functionality as JScript is single threaded. Is there any other way to implement this? Use of setinterval or settimeout functions have been ruled out because they provide asynchronous wait not sychronous. Other option i.e. writing pause/sleep/wait function using Date object is also ruled out because it keeps the browser busy in doing some activity instead of relinquishing control for some other event to complete and then return control back to same previous method from where this wait/sleep/pause was called. Any help please?
ASKER
Thanks Gurvinder but I have already it with reason out and mentioned in my query also. :-)
ASKER
Thanks Gurvinder but I have already ruled it out with reason and mentioned in my query also. :-)
what kind of wait are you looking for, btw, if you want the browser to allow you to do something without the wait being asynchronous?
ASKER
Actually its linked with my other open query https://www.experts-exchange.com/questions/26725224/Status-of-XMLHTTPRequest-object-is-12031-on-call-of-its-Send-method.html only.
For some reason my synchronous XMLHttp calls error out with 12031 status 1 out of 10 times so I thought of making them asynchronous and tracking the call output with OnReadyChangeState event. Now the challenge I am facing is with keeping the calling function in wait state until corresponding OnReadyChangeState event returns relevant output.
For some reason my synchronous XMLHttp calls error out with 12031 status 1 out of 10 times so I thought of making them asynchronous and tracking the call output with OnReadyChangeState event. Now the challenge I am facing is with keeping the calling function in wait state until corresponding OnReadyChangeState event returns relevant output.
you can add the overlaid loading (or please wait) image on the screen, so that user cannot take any action.
http://visionmasterdesigns.com/tutorial-adding-a-ajax-spinner-in-the-center-of-web-page-using-prototype/
http://itprism.com/blog/ajax-loading-overlay
http://visionmasterdesigns.com/tutorial-adding-a-ajax-spinner-in-the-center-of-web-page-using-prototype/
http://itprism.com/blog/ajax-loading-overlay
ASKER
Gurvinder
Actually these synchronous calls are being made from mid of some request processing so there is no scope of holding the user to perform the next activity. Basically a synchronous XMLHTTP call is being made and based on its output some other processing is happening to suffice the desired request.
Had I got some way to implement synchronous wait in a calling method and relinquish the execution control to OnReadyChangeState event for that particular waiting period, I would have achieved my objective.
Actually these synchronous calls are being made from mid of some request processing so there is no scope of holding the user to perform the next activity. Basically a synchronous XMLHTTP call is being made and based on its output some other processing is happening to suffice the desired request.
Had I got some way to implement synchronous wait in a calling method and relinquish the execution control to OnReadyChangeState event for that particular waiting period, I would have achieved my objective.
<<Actually these synchronous calls are being made from mid of some request processing>>
please elaborate on this
please elaborate on this
ASKER
Actually scenario is like this
function doSomething(){
//some statements of code
var xmloutput = SyncXMLHTTPCall(URL, XMLInput);
//some more manipulation over xmloutput received in previous state
}
And this function doSomething also could be called in of the other existing JS functions so there is no scope of shifting following statements into some callback JS function.
function doSomething(){
//some statements of code
var xmloutput = SyncXMLHTTPCall(URL, XMLInput);
//some more manipulation over xmloutput received in previous state
}
And this function doSomething also could be called in of the other existing JS functions so there is no scope of shifting following statements into some callback JS function.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
function pausecomp (millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}