Semaphore es-toolkit
Limits the number of asynchronous tasks that can execute simultaneously.
Usage
Semaphore(capacity)
Use Semaphore when you want to limit the number of asynchronous tasks that can execute concurrently. It's particularly useful in situations where you need to control resource usage, such as database connection pools, API call rate limiting, or file download limits.
Parameters
capacitynumberrequired
The maximum number of tasks that can execute concurrently. Must be a positive integer.
Properties
capacity(number): The maximum number of tasks that can execute concurrently.available(number): The number of currently available permits. If0, all permits are in use.
Methods
acquire(() => Promise<void>): Acquires permission to execute an asynchronous task, or waits until permission is granted.release(() => void): Returns permission so that the next waiting task can execute.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.