【发布时间】:2016-11-16 13:49:05
【问题描述】:
如果我对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] ?
}
});
【问题讨论】:
-
是的,迭代器和数组需要顺序。尝试维护对象键的顺序
标签: javascript asynchronous async.js