source: node_modules/es-toolkit/dist/array/limitAsync.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 398 bytes
Line 
1import { Semaphore } from '../promise/semaphore.mjs';
2
3function limitAsync(callback, concurrency) {
4 const semaphore = new Semaphore(concurrency);
5 return async function (...args) {
6 try {
7 await semaphore.acquire();
8 return await callback.apply(this, args);
9 }
10 finally {
11 semaphore.release();
12 }
13 };
14}
15
16export { limitAsync };
Note: See TracBrowser for help on using the repository browser.