The permit must be released after use by calling release(). Failure to
release reduces available concurrency until the permit is garbage collected
(JavaScript has no RAII like Rust's Drop).
Prefer Semaphore.withPermit for automatic acquire/release with
try/finally semantics. Manual acquire()/release() requires a
try/finally block to avoid leaking permits on exceptions.
The well-known symbol Symbol.toStringTag used by Object.prototype.toString().
Returns 'SemaphorePermit' so that Object.prototype.toString.call(permit)
produces '[object SemaphorePermit]'.
Methods
release
release():void
Releases the permit back to the semaphore, allowing another waiting
operation to proceed (or incrementing the available count).
Calling release() more than once is a no-op (idempotent), matching
the behavior of MutexGuard.unlock().
Returns void
Example
constsem = Semaphore(1); constpermit = awaitsem.acquire(); permit.release(); permit.release(); // no-op, safe to call again
A permit acquired from a Semaphore.
The permit must be released after use by calling
release(). Failure to release reduces available concurrency until the permit is garbage collected (JavaScript has no RAII like Rust'sDrop).Prefer Semaphore.withPermit for automatic acquire/release with
try/finallysemantics. Manualacquire()/release()requires atry/finallyblock to avoid leaking permits on exceptions.Since
1.10.0
See
Semaphore
Example