I am creating a server in Nodejs to retrieve data from some database. I had been working with the asynchronous library for some time and figured out some things, such as putting a waterfall inside a parallel function.
I came across a problem when I first need to execute a query, and then use this query result in other queries that can run at the same time. 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 use it in parallel functions.
source share