我需要进行多次异步调用,并确保结果与调用保持的顺序。如何使用async
库实现这一目标?
async.map(['item1', 'item2', 'item3'], function (itemName, callback){
// Ajax GET item on server
// ...
// Once we have the item, return it
callback(null, item);
}, function(error, results){
// The results array is not necessarily sorted by order of calls
// It can be [item2, item3, item1]
// I want to ensure it will always be [item1, item2, item3]
});
答案 0 :(得分:0)