0
如果我对async.map
进行了一系列调用,结果是否保证了顺序?或者结果只是请求完成的顺序?例如async.map保证结果是按顺序传递的吗?
var requestList = [
{ method: 'GET', url: '/something1' },
{ method: 'GET', url: '/something2' },
{ method: 'GET', url: '/something3' }];
// async map the requests together, and handle the result in
// the callback.
async.map(requestList, function(obj, callback) {
request(obj, function(error, response, body) {
if(!error && response.statusCode == 200) {
var body = JSON.parse(body);
callback(null, body);
} else {
callback(error || response.statusCode);
}
});
}, function(err, result) {
if(err) {
console.log('Error!');
} else {
// is result guarenteed to be in the order: [/something1, /something2, /something3] ?
}
});
是的,顺序是迭代器和数组的保证。尝试保持对象键的顺序 – megawac