I have a code snippet like the following.
async.parallel({
foo: function(call) {
request.get('...?node=foo', function (error, response, body) {
var last=JSON.parse(body);
call(null,last.data.result);
});
},
bar: function(call) {
request.get('...node=bar', function (error, response, body) {
var last=JSON.parse(body);
call(null,last.data.result);
});
}
}, function(err, results) {
callback(results)
});
but I want to that in loop...that is to say,like the following.
var node = ['foo', 'bar'];
async.parallel({
for (var i = 0; i < node.length; i++) {
node[i]: function(call) {
request.get('...?node=' + node[i] + '', function(error, response, body) {
var last = JSON.parse(body);
call(null, last.data.result);
});
}
}
}, function(err, results) {
callback(results)
});
it does not work...how to make it? can you help me?
async.map()