sindresorhus / p-limit

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

Limit concurrency of single function #86

Open Richienb opened 4 months ago

Richienb commented 4 months ago

I have a use case where I have a function that mustn't be running more than x times concurrently because of API restrictions.

I propose the addition of the named export:

function pLimitFunction(function_, concurrency) {
    const limit = pLimit(concurrency);

    return (...arguments_) => limit(() => function_(...arguments_));
}

This is similar to #74, except we also define the limiter within the function.

sindresorhus commented 4 months ago

Sounds good.

I think the concurrency parameter should be an options-object instead.

What about naming it limitFunction?