Creates a new semaphore with the given initial number of permits and maximum number of permits.
The maximum number of permits.
Optional
initialValue: numberThe initial number of permits available. Defaults to maxValue
.
Acquires a permit from the semaphore, waiting if necessary until one is available.
Optional
signal: null | AbortSignalAn optional AbortSignal to cancel the acquire operation.
A promise that resolves to a function that releases the acquired permit.
The maximum number of permits.
Releases a permit, returning it to the semaphore.
Tries to acquire a permit from the semaphore immediately, without waiting.
The number of permits to acquire.
true
if the permits were acquired, false
otherwise.
A counting semaphore implementation.
A semaphore maintains a set of permits. Each
acquire
call blocks if necessary until a permit is available, and then takes it. Eachrelease
call adds a permit, potentially releasing a blocking acquirer.The semaphore is initialized with a given number of permits. The number of permits can be increased up to a maximum value.