The number of spots currently available for callers before they will be queued.
The number of callers that are still waiting to run.
The number of callers currently running. Callers must always remember to call release() when done to ensure this number is decremented appropriately.
Queues the caller until a spot is available.
A Promise that will be resolved when a slot is available.
Notifies the semaphore that the given number of slots have become available. If any callers have been queued, they will be run in the newly available slots.
The number to spots to make available.
Limits access to a pool of resources by restricting how many callers can run at a time. Any callers above the allowed amount will be queued until a spot is released.
Best Practices
release()
inside afinally
block makes this easy. See the example below.