es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
17 lines (14 loc) • 398 B
JavaScript
import { Semaphore } from '../promise/semaphore.mjs';
function limitAsync(callback, concurrency) {
const semaphore = new Semaphore(concurrency);
return async function (...args) {
try {
await semaphore.acquire();
return await callback.apply(this, args);
}
finally {
semaphore.release();
}
};
}
export { limitAsync };