I had same problem, I need synchronous request for my app. I did same
thing as you (making asynchronous rquests and wait to finish before
send the other one). But, on a newer version, I modified my app logic
to be able to use asynchronous requests. Now I can start as many
requests as need it and when are need it and only care when all are
finished, not each of them, This change brought me about 200% speed
increase for that part of the code.

On Jun 29, 10:29 pm, Sergio Viudes <[email protected]> wrote:
> Thanks for your reply!
>
> I used HTTPRequest inside a workerPool, thanks.
>
> I wanted to do synchronous postbacks, I know it's not possible but I
> "simulated" it with a recursive function like this:
>
> function doWork(array, arrayIndex){
>   if(arrayIndex < array.length){
>     var request = blah,blah,blah....
>     request.onreadystate = function(){
>         if(request.readyState == 4){
>           do_some_work_with_array[arrayIndex];
>           doWork(array, arrayIndex + 1);
>         }
>     }
>   }
>
> }
>
> And call to: doWork(myArray, 0);
>
> It's something like "serial calls". A call is made only if previous
> has ended.
>
> Thanks!
>
> On 29 jun, 20:49, Michael Nordman <[email protected]> wrote:
>
> > On Sun, Jun 28, 2009 at 11:20 PM, Sergio Viudes <[email protected]> wrote:
>
> > > Hello. I started working with gears. Now I'm doing a synchronization
> > > module for my app. This module gets data from a rpc server and insert
> > > it to my sqlite local database. I want to use workerPool class to
> > > maintain UI responsive. I have 2 questions:
>
> > > 1 - What do you think is better, do asynchronous calls with
> > > XMLHTTPRequest to get the data from rpc server in main thread and pass
> > > data to a worker pool that do "inserts" to database or use HTTPRequest
> > > to get data, and insert it, inside the worker pool?
>
> > These pretty much amount to the same thing.
>
> > If the request is being initiated by the worker, you have one less step
> > between reading the response data and inserting into the DB since you won't
> > have to send a message to a worker... so i would say its slightly preferable
> > to use HTTPRequest in the worker.
>
> > > 2 - Can I do synchronous calls inside a workerpool? (I think I can't,
> > > because HTTPRequest can't do syncrhonous calls, only asyncrhonous...)
>
> > Nope... gears HTTPRequest only supports an async interface.

Reply via email to