A counting semaphore for async functions that manages available permits. Semaphores are mainly used to limit the number of concurrent async tasks.
Each acquire
operation takes a permit or waits until one is available.
Each release
operation adds a permit, potentially allowing a waiting task to proceed.
The semaphore ensures fairness by maintaining a FIFO (First In, First Out) order for acquirers.
new
Semaphore(capacity: number)
Creates an instance of Semaphore.