[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to implement synchronous pause with JScript?

Posted on 2011-02-13
11
Medium Priority
?
811 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:sachitjain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34885742
looks like this code i had was just waiting for you

function pausecomp (millis)
{
      var date = new Date();
      var curDate = null;
      
      do { curDate = new Date(); }
      while(curDate-date < millis);
}
0
 
LVL 12

Author Comment

by:sachitjain
ID: 34885763
Thanks Gurvinder but I have already it with reason out and mentioned in my query also. :-)
0
 
LVL 12

Author Comment

by:sachitjain
ID: 34885766
Thanks Gurvinder but I have already ruled it out with reason and mentioned in my query also. :-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34885779
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?
0
 
LVL 12

Author Comment

by:sachitjain
ID: 34885813
Actually its linked with my other open query http://www.experts-exchange.com/Programming/Languages/Scripting/JScript/Q_26725224.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.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34885865
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
0
 
LVL 12

Author Comment

by:sachitjain
ID: 34885969
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.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34886073
<<Actually these synchronous calls are being made from mid of some request processing>>
please elaborate on this
0
 
LVL 12

Author Comment

by:sachitjain
ID: 34886114
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.
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1500 total points
ID: 34914347
why don't you turn it into this?
function doSomething(){
      //some statements of code
      var xmloutput = SyncXMLHTTPCall(URL, XMLInput);
      //some more manipulation over xmloutput received in previous state
}


turn it into

function doSomething(){
      //some statements of code
      var xmloutput = SyncXMLHTTPCall(URL, XMLInput);
      setTimeout("nextFunction()", 5000); // a delay of 5 seconds before next function is called
}

function nextFunction()
{
   //some more manipulation over xmloutput received in previous state
}

0
 
LVL 12

Author Closing Comment

by:sachitjain
ID: 35340752
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question