我正在使用 npm 异步库(https://caolan.github.io/async/docs.html)来限制并行请求的数量。下面是我的代码:
async.eachLimit(listOfItemIds, 10, function(itemId)
{
console.log("in with item Id: ",itemId);
}, function(err) {
if(err)
{
console.log("err : ",err);
throw err;
}
});
Run Code Online (Sandbox Code Playgroud)
但它不会对所有 listOfItemIds 执行,它只对前 10 个执行并退出。
以下是输出:
in with item id: 252511893899
in with item id: 142558907839
in with item id: 273235013353
in with item id: 112966379563
in with item id: 192525382704
in with item id: 253336093614
in with item id: 112313616389
in with item id: 162256230991
in with item id: 282981461384
in with item …Run Code Online (Sandbox Code Playgroud)