• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Function chain with asynchronized request

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a function call in my JavaScript is asynchronized by nature. The function sends out a request to server and needs to wait for the result. I know that is error-prone. One sugestion I received is to break the function apart and settimeout to poll the result. Although that might work for this case, but we don't want to wait for arbitrary time. I am just wondering whether we could implement a JavaScript FIFO queue to handle this.

We could create a chain of functions, by placing the next function to execute in the queue. When the asynchronous request is complete, the returned script activates the last function placed into the queue. I am just wondering whether that is doable or anyone have experience on that.

Thanks,
Burt
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you sending the response to the server?
 
bujin wang
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can have two hidden frames and a JavaScript object to handle background communication with the server.
* The "reqeust" frame contains a HTML form which is posted to the server to initiate server processing.
* The "response" frame is set tas the target for the server response and has an onLOad event attached to its body tag to manage the data returned.
* The CRequest object contains methods to set the form data and activate the post to the server.

Any ideas?
[ August 18, 2004: Message edited by: bujin wang ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can have onload handler on the frame that is being submitted, this frame can tell you when the process is done and send the request to the frame that is controlling all of the information. That controlling frame can then start the next process.

That is the basic idea...

Eric
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic