I have below function which fetches data in parallel. Once the fetching data is done the result will be available via 'results' variable in the callback function. I needs to parameterize instead of hard coding 'products', 'images' etc. I need to be able to pass an array. (i.e I need to say var fetchInParallel = function (id, res, names)
) where names = ['products', 'images']
How would I do that? I tried using forEach with no luck.
var fetchInParallel = function (id, res) {
async.parallel(
[
function (callback) {
commonService.findById('products', id, function (result) {
callback(false, result);
})
},
function (callback) {
commonService.findById('images', id, function (result) {
callback(false, result);
})
}
],
function (err, results) {
// handle errors code
var products = results[0];
var volatile = results[1];
var target = stitch(products,images);
res.send(target)
}
);
}