Cordova – How to wait until the callback function returns?

I am using phonegap to make an Android application. I am using phonegap’s Storage api to query the database. This is my code:

function directPath(src, dest)
{
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db. transaction(queryDB, errorCB);
return arrayroute;
}

function queryDB(tx)
{
tx.executeSql(query, [], querySuccess, errorCB);
}

function querySuccess(tx,results) {
//Write some code here.
}

function errorCB(err) {
alert("Error in SQL: "+ err);
}

The problem is that I want to wait until the callback method querySuccess finishes execution before returning from the directPath method .

Don’t try to fight against asynchrony: your app may eventually seem unresponsive to users. For later For any code executed, please use the querySuccess callback.

I am using phonegap to make an Android application. I am using phonegap’s Storage api to query the database. This is my code:

function directPath(src, dest)
{
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo" , 200000 );
db.transaction(queryDB, errorCB);
return arrayroute;
}

function queryDB(tx)
{
tx .executeSql(query, [], querySuccess, errorCB);
}

function querySuccess(tx,results) {
//Write some code here.
}

function errorCB(err) {
alert("Error in SQL: "+ err);
}

The problem is that I want to wait until the callback method querySuccess Finish execution before returning from the directPath method.

Don’t try to fight against asynchrony: your application may eventually appear to be unresponsive to the user. For any code that must be executed later , Please use querySuccess callback.

Leave a Comment

Your email address will not be published.