I'm building a server in Nodejs to retrieve data from some database. I've worked with the async library for some time now and figured out some things like putting a waterfall inside a parallel function.
I stumbled upon a problem where I first need to execute a query and then use that query's result in other queries that can be executed concurrently. The code looks something like this:
async.waterfall([
function(callback) {
connection.query( query,
function(err, rows, fields) {
if (!err) {
callback(null,rows);
} else {
callback(null,"SORRY");
}
}
);
},
async.parallel([
function(resultFromWaterfall,callback) {
connection.query(query,
function(err, rows, fields) {
if (!err) {
callback(null,rows);
} else {
callback(null,"SORRY");
}
}
);
},
function(resultFromWaterfall,callback) {
connection.query(query,
function(err, rows, fields) {
if (!err) {
callback(null,rows);
} else {
callback(null,"SORRY");
}
}
);
}
])
], finalCallback
);
Now my problem is to access the result from the waterfall function and to use it in the parallel functions.