nicolas-van/modern-async

forEachLimit is ignoring the concurrent paramter

Closed this issue · 1 comments

See this Code:

//@ts-ignore
var {forEachLimit}=require('modern-async')

var ar=[]
for(let i=0;i<=100;i++) ar.push(i)

forEachLimit(ar,async item=>{
  await delay(1000)
  console.log(item)
},5)
function delay(ms){return new Promise(resolve=>setTimeout(resolve,ms))}

It should show every 1 seconds 5 items. But it shows after 1 second all the items.
I found the bug and I wanted to fix it:

In the file forEachLimit.js:

async function forEachLimit (iterable, iteratee, concurrency) {
  await mapLimit(iterable, async (v, i, t) => {
    iteratee(v, i, t)
  }, concurrency)
}

missing await before iteratee(v, i ,t)

I wanted to fix it but the current version in GitHub is different (in development).
Can you provide hotfix and publish it to NPM as 1.0.4?
It's really a security issue for servers to handle too many requests at the same time.

By the way, thank you for you awesome library.

Version 1.0.4 has been published with the fix.

Thank you for reporting.