HttpRequest in a worker pool or xmlHttpRequest in main worker?

15 views
Skip to first unread message

Sergio Viudes

unread,
Jun 29, 2009, 2:20:08 AM6/29/09
to Gears Users
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?

2 - Can I do synchronous calls inside a workerpool? (I think I can't,
because HTTPRequest can't do syncrhonous calls, only asyncrhonous...)

Michael Nordman

unread,
Jun 29, 2009, 2:49:49 PM6/29/09
to gears...@googlegroups.com
On Sun, Jun 28, 2009 at 11:20 PM, Sergio Viudes <djpep.dj@gmail.com> 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.
 

Sergio Viudes

unread,
Jun 29, 2009, 3:29:25 PM6/29/09
to Gears Users
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 <micha...@google.com> wrote:

Eduard Martini

unread,
Jun 30, 2009, 7:55:09 AM6/30/09
to Gears Users
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.

Bala

unread,
Aug 28, 2009, 8:03:36 AM8/28/09
to Gears Users
Hi!.. I am try to implement Gears concept in my forth coming project.I
get example's of files capturing and local database creation with out
ajax help.For real time app i need to known how local database created
and synchronized from server database and after doing some updation,
process how to upload local database to server database. I am using
Java,My-sql in server side and SQLite in local server.

I don't have an idea to get DB data as JSON. I used Ajax to get
response
as a string only but i don't know how get DB.Pls can u suggest with
example
similarly offline to online.

Pls mail reply me on balaji...@gmail.com


Regards
Balaji.C
Reply all
Reply to author
Forward
0 new messages