I want to return the value from within nested callbacks. Below is the pseudo code:
dataSetFinal = function1()
within function1
database is queried to get dataSet1
call function2, using dataSet1 as arguments
within function2
query database to get dataSet2
return dataSet2
return dataSet2
Here is my attempt to make it work
dataSetFinal = function1("arg1", function(err, rows){
client.query(sql1, function(err,rows){
function2(rows[0].userId, function(err, rows){
client.query(sql2, function(err, rows){
return rows;
});
});
});
});
But I'm unable to figure out how to get function1 to return function2's "rows".
returnkeyword before each method call? Ex.function1("arg1", function(err, rows){ return client.query(sql1, function(err,rows){ return 1;} );?