happy-rusty
    Preparing search index...

    Interface SemaphorePermit

    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'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.

    1.10.0

    const sem = Semaphore(2);
    const permit = await sem.acquire();
    try {
    await doWork();
    } finally {
    permit.release();
    }
    interface SemaphorePermit {
        "[toStringTag]": "SemaphorePermit";
        release(): void;
        toString(): string;
    }
    Index

    Properties

    Methods

    Properties

    "[toStringTag]": "SemaphorePermit"

    The well-known symbol Symbol.toStringTag used by Object.prototype.toString(). Returns 'SemaphorePermit' so that Object.prototype.toString.call(permit) produces '[object SemaphorePermit]'.

    Methods

    • 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

      const sem = Semaphore(1);
      const permit = await sem.acquire();
      permit.release();
      permit.release(); // no-op, safe to call again
    • Custom toString implementation.

      Returns string

      const sem = Semaphore(2);
      const permit = await sem.acquire();
      console.log(permit.toString()); // 'SemaphorePermit'
      permit.release();
      console.log(permit.toString()); // 'SemaphorePermit(<released>)'