Do calls to handleRequest have to be atomic?

0 views
Skip to first unread message

toriaezunama

unread,
Nov 25, 2009, 2:47:16 AM11/25/09
to QuickConnect
I have a situation similar to the following setup where the 3
successive calls handleRequest in main.js cause the results returned
from Step1_Part2_BCF to be returned as if they called from Step3_BCF.
This is because by the time Step1_Part2_BCF is called the global
variable 'executionKey' has been set to that for Step3_BCF, and the
resulting call to Step1_Part2_BCF is set to return to an execution
object with that key.

Appologies for the long explanation by is this the correct behaviour?

// databaseDefinition.js
database = new DataAccessObject('dbName', 1.0, '', 1000000, false);

// mappings.js
mapCommandToBCF('Step1', Step1_Part1_BCF);
mapCommandToBCF('Step1', Step1_Part2_BCF);
mapCommandToBCF('Step2', Step2_BCF);
mapCommandToBCF('Step3', Step3_BCF);

// functions.js
function Step1_Part1_BCF(parameters) {
var query = "SELECT * FROM table1";
database.getData(query, parameters);
}

function Step1_Part2_BCF(parameters) {
var query = "SELECT * FROM table1";
database.getData(query, parameters);
}

function Step2_BCF(parameters) {
var query = "SELECT * FROM table1";
database.getData(query, parameters);
}

function Step3_BCF(parameters) {
var query = "SELECT * FROM table1";
database.getData(query, parameters);
}

// main.js
handleRequest('Step1');
handleRequest('Step2');
handleRequest('Step3');

Lee Barney

unread,
Nov 25, 2009, 6:01:26 PM11/25/09
to quickconn...@googlegroups.com
What you want to do here is to map all of these BCFs to one command in the order you want them executed.  Then you can make one call to handleRequest.

What you have to remember is that all of the database access to the in-browser HTML 5 database is asynchronous.  That is why your data came back intermingled.

If you do all of these from one singe handleRequest call the framework will linearize the asynchronous calls for you.  They will still be asynchronous but they will execute in the order you define them.


lee


--

You received this message because you are subscribed to the Google Groups "QuickConnect" group.
To post to this group, send email to quickconn...@googlegroups.com.
To unsubscribe from this group, send email to quickconnectiPh...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/quickconnectiPhone?hl=en.



toriaezunama

unread,
Nov 25, 2009, 8:31:05 PM11/25/09
to QuickConnect
Thanks for quick reply Lee,

Depending on the situation I may call just Step1, or Step1 then Step2,
or Step1, Step2, Step3 in order so I can't just fix this with one
function. I'll extend my command list to include special cases for
each of these.
As stupid as it sounds i hadn't thought of doing this.
Still, I learnt a fair bit about the internals as a result ;)

Thanks


On Nov 26, 8:01 am, Lee Barney <barney....@gmail.com> wrote:
> What you want to do here is to map all of these BCFs to one command in the
> order you want them executed.  Then you can make one call to handleRequest.
>
> What you have to remember is that all of the database access to the
> in-browser HTML 5 database is asynchronous.  That is why your data came back
> intermingled.
>
> If you do all of these from one singe handleRequest call the framework will
> linearize the asynchronous calls for you.  They will still be asynchronous
> but they will execute in the order you define them.
>
> lee
>
> > quickconnectiPh...@googlegroups.com<quickconnectiPhone%2Bunsu...@googlegroups.com>
> > .

Lee Barney

unread,
Nov 25, 2009, 8:51:30 PM11/25/09
to quickconn...@googlegroups.com
If the combinations are known and fixed you could make a mapping for each one.  Is each possibility the result of a different event?

Lee

To unsubscribe from this group, send email to quickconnectiPh...@googlegroups.com.

toriaezunama

unread,
Nov 29, 2009, 9:37:55 PM11/29/09
to QuickConnect
Writing a separate mapping for each combination means writing a new
VCF function per mapping. This is because depending on the case the
VCF has to perform the equivalent functionality of either 1,2 or 3
VCFs.

I could wrap calls to the existing VCFs in a holder function that
passes on the relevent data/parameters to the existing VCFs and map
this function to the command, but this solution doesn't scale very
well to larger no.s / combinations.

My solution is as follows:
// added to - functions.js
var gCmdStack = [];

// Get next cmd of the stack and execute - should be called as the
last function in EVERY command
function ProcessCmdStack() {
if(gCmdStack.length > 0) {
var cmdObj = gCmdStack.shift();
handleRequest(cmdObj[0], cmdObj[1]);
}
return true;
}

function QueueCmd(aCmd, aParams) {
if(!aParams)
aParams = [];
gCmdStack.push([aCmd, aParams]);
}

For every command that needs to be sequentially executed i add the
following line as a VCF to the command map

// mapping.js
mapCommandToVCF('cmd', ProcessCmdStack);

Then to stack commands i just call
QueueCmd('cmd', parameters);
in the same way i would call handleRequest('cmd');


On Nov 26, 10:51 am, Lee Barney <barney....@gmail.com> wrote:
> If the combinations are known and fixed you could make a mapping for each
> one.  Is each possibility the result of a different event?
>
> Lee
>
> > <quickconnectiPhone%2Bunsu...@googlegroups.com<quickconnectiPhone%252Buns...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages