Connecting Tech Pros Worldwide Help | Site Map

Simulating synchronous calls in javascript

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:35 PM
Chris
Guest
 
Posts: n/a
Default Simulating synchronous calls in javascript


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


  #2  
Old July 23rd, 2005, 05:36 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Simulating synchronous calls in javascript



Chris wrote:

[color=blue]
> 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?[/color]

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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.