Creates a new semaphore with the given initial number of permits and maximum number of permits.
The maximum number of permits.
OptionalinitialValue: numberThe initial number of permits available. Defaults to maxValue.
The current number of available permits.
The current number of available permits.
Acquires a permit from the semaphore, waiting if necessary until one is available.
Optionalsignal: AbortSignal | nullAn optional AbortSignal to cancel the acquire operation.
A promise that resolves to a lease when the permits are acquired.
The maximum number of permits.
The maximum number of permits.
Releases permits back to the semaphore.
Any pending acquisitions will be processed asynchronously after this call.
The number of permits to release.
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 general/counting strong semaphore implementation.
A semaphore maintains a set of permits. Each
acquirecall blocks if necessary until a permit is available, and then takes it. Eachreleasecall 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.
The order of permit acquisition is guaranteed to be FIFO.