I have this recursive function where I need to return some data after the function completes.
// Set Up my Database paramaters
var coachdb = new AWS.DynamoDB({
...
});
// This tracks the array index of the current parameter.
var pos = 0;
function callback(err, data) {
if (err) {
console.log(err, err.stack);
} else if (data.Items.length > 0) {
//return data.Items // Where I need something here to return data
} else if (++pos < params.length) { // Increment the index.
coachdb.query(params[pos], callback); // Recursive call.
}
}
coachdb.query(params[pos], callback); // Kick off the series of calls
Everything inside the function is working just fine. I am querying my database just fine iterating through the possible parameters until the right one is found and then the function ends.
However I am not sure how to pass the data outside the function. Any help would be appreciated.