By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,880 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,880 IT Pros & Developers. It's quick & easy.

Simulating synchronous calls in javascript

P: n/a

Hi.
I have a ibrary I'm trying to use via javascript within IE. This
library uses an asynchronous model where I call into a function and
pass it a callback function as one of its arguments. My method returns
immediately, and the callback function is called shortly thereafter...
virtually immediately.

I want to find a way to simplify my code by finding a way to simulate
synchronous behavior for those functions. It's a little awkward to
have to string together calling functions and callbacks all over the
place, particularly when I need to maintain some kind of state between
those calls. The "user experience" is unlikely to suffer with a
synchronous model, IMO, since these async methods always return very
quickly.

So, how can I best simulate synchronous behavior when dealing with
asynchronous functions?
thanks,
Chris

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Chris wrote:

I have a ibrary I'm trying to use via javascript within IE. This
library uses an asynchronous model where I call into a function and
pass it a callback function as one of its arguments. My method returns
immediately, and the callback function is called shortly thereafter...
virtually immediately.

I want to find a way to simplify my code by finding a way to simulate
synchronous behavior for those functions. It's a little awkward to
have to string together calling functions and callbacks all over the
place, particularly when I need to maintain some kind of state between
those calls. The "user experience" is unlikely to suffer with a
synchronous model, IMO, since these async methods always return very
quickly.

So, how can I best simulate synchronous behavior when dealing with
asynchronous functions?


Perhaps show us what exactly you are doing, which API, which objects,
which methods in IE you are using which require a callback function and
then maybe we can tell us whether there is a synchronous way. If you are
using MSXML and its XMHTTP request object for instance then the open
method has a third argument that you can set to false if you really want
synchronous processing. But that blocks the browser while the request is
sent, the answer is received and processed so it is usually not a good
idea even if you think that it normally happens "virtually immediately".
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.