A simple Semaphore implementation which provides a limited queue for ensuring proper concurrency.
Param: max
The maximum number of tasks which are allowed concurrently.
Example: Using a Semaphore
// Some async function that takes time to execute functionfn(x) { returnnewPromise(resolve=> { setTimeout(() => { console.log(x); resolve(x); }, 1000)); } };
// Create a Semaphore and add many concurrent tasks constsemaphore = newSemaphore(1); for ( letiofArray.fromRange(100) ) { semaphore.add(fn, i); }
A simple Semaphore implementation which provides a limited queue for ensuring proper concurrency.
Param: max
The maximum number of tasks which are allowed concurrently.
Example: Using a Semaphore