sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
2.06k stars 106 forks source link

Need to pass functions being called in the limit function? #13

Closed dwalintukan closed 5 years ago

dwalintukan commented 5 years ago

Considering the following code:

const myFunc = (var1) => {...}

const promises = []
promises.push(limit(async (var1) => {
  myFunc(var1);
}, passedVar1)
await Promises.all(promises)

Should I be passing myFunc as part of the args when passing it to the limit generator? Or is the outside reference ok?

sindresorhus commented 5 years ago

Any function passed to limit() is limited, so if that function calls another one, it will naturally be limited too as it's called by the limited function. So in short, yes.