I have a task where I need to execute a SQL SELECT statement and save the results. Then, those results need to be passed into a function to generate a graph using the data points provided. Refer to the code snippet below for details.
var dataKWhr = getCoverageAndKWhr();
console.log(dataKWhr);
createGraph(dataKWhr);
console.log("Graph created");
The execution of the getCoverageAndKWhr
function begins but the subsequent part of the original function proceeds with the log statement and createGraph
. This leads to failure as dataKWhr is still undefined at this point since its value has not been returned from getCoverageAndKWhr()
.
I am looking for a solution that does not involve implementing a fixed time delay. Is there a method to ensure that the first line completes before moving on?
This situation pertains to a PhoneGap mobile application integrated with jQueryMobile and currently undergoing testing on Android.