Optional
maxCount: numberReleases the Semaphore a specified number of times.
Optional
releaseCount: numberThe number of times to exit the Semaphore. undefined
will exit the Semaphore once (1).
Adding the specified count to the Semaphore would cause it to exceed maxCount.
releaseCount
. If count is already 0
before this function
is called, the function also allows releaseCount
Promises blocked by waitAsync to enter the Semaphore.releaseCount
will cause Semaphore to exceed maxCount, Promises waiting to
enter the Semaphore are not counted in. This behavior is currently just to align with the Win32
ReleaseSemaphore
API.Tries to enter the Semaphore immediately.
true
if the caller has successfully entered the Semaphore; false
otherwise.
Blocks the caller asynchronously until it can enter the Semaphore, reached the specified timeout, or has been aborted.
Optional
timeoutMs: numbermaximum time in milliseconds to wait.
Optional
signal: AbortSignala signal used to cancel the wait.
true
if the caller has entered Semaphore successfully; false
if the specified timeout has been reched.
the specified signal
has been aborted. If the signal has been aborted with explicit reason,
the AbortSignal.reason will be thrown.
If the caller has successfully entered the Sempahore, count will be decreased by 1.
Blocks the caller asynchronously until it can enter the Semaphore or has reached the specified timeout.
Optional
signal: AbortSignala signal used to cancel the wait.
always true
, as the returned Promise won't fulfill until it enters the Semaphore or has been aborted,
which will result in rejection.
the specified signal
has been aborted. If the signal has been aborted with explicit reason,
the AbortSignal.reason will be thrown.
If the caller has successfully entered the Sempahore, count will be decreased by 1.
Limits the number of concurrent asynchronous processes that can access a resource.
Remarks
A Semaphore is a synchronization object that maintains a count between zero and an optional, specified maximum value. The count is decremented each time a caller enters the Semaphore, and incremented each time a caller releases the Semaphore.
To enter the Semaphore, call wait or waitAsync. To release the Semaphore, call release. When count reaches zero, subsequent calls to waitAsync will block asynchronously until the Semaphore is released elsewhere. If multiple callers are blocked asynchronously, there is no guaranteed order, such as FIFO or LIFO, that controls who enter the Semaphore.