Thanks!
This is what I need

On 22 ноя, 12:15, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> > I have two calls run asyncronously
> > Two - is an example - they may be N-calls :)
>
> I'd recommend avoiding that unless the async calls are to *different*
> servers, and if you do two at once, certainly never do more than two
> at once. Run just a single async request at a time, two if you
> absolutely have to, and chain them using the `success` handler.
>
> Why? Because browsers (and some servers) clamp down the number of
> connections to a given server at the same time. Mostly, with modern
> desktop browsers, you can expect the browser will allow four[1] (up
> from the previous figure of two), but IE will drop down to only
> allowing two if it detects a dial-up connection and you don't know
> what the next "dot" rev of any browser may do. Also, mobile browsers
> have lower limits.
>
> In terms of mechanism, I'd probably have a pending count (no need for
> global variables):
>
> * * * *
> // Start the requests defined in the array `requests`, call `callback`
> // when they've all finished.
> function sendMultipleRequests(requests, callback) {
>     var req, pending;
>
>     // Prep and start each request. We assume the objects have a `url`
>     // property and a `params` property.
>     pending = 0;
>     while (pending < requests.length) {
>         // Get this request
>         req = requests[pending];
>
>         // Hook into the onComplete, respecting the previous one if
> any
>         req.params = req.params || {};
>         req.params.onComplete = req.params.onComplete
>             ? req.params.onComplete.wrap(reqComplete)
>             : reqComplete;
>
>         // Start and count this request
>         new Ajax.Request(req.url, req.params);
>         ++pending;
>     }
>
>     function reqComplete() {
>         --pending;
>         if (pending <= 0) {
>             // All done, call the callback.
>             // Note that there's no race condition with the loop above
> (e.g.,
>             // there's no possibility we'll be called and decrement
> `pending`
>             // to 0 while the loop above is still incrementing it)
> because
>             // JavaScript on browsers is single-threaded unless you
> explicitly
>             // use the web workers stuff, which we aren't.
>             callback();
>         }
>     }
>
> }
>
> [1]http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-conne...
>
> HTH,
> --
> T.J. Crowder
> Independent Software Engineer
> tj / crowder software / com
> www / crowder software / com
>
> On Nov 21, 8:40 pm, buda <www...@pochta.ru> wrote:
>
>
>
>
>
>
>
> > I have two calls run asyncronously
> > I need to wait when they both is comleted and only then do somthing
> > Two - is an example - they may be N-calls :)
>
> > What is the right method to do it?
> > Is theere an object somthing AsyncWaitFor(AjaxCall1...AjaxCallN)?

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to