Skip to content

semaphore

A counting semaphore that limits how many async operations run at once.

Adapted from es-toolkit’s Semaphore (MIT, see THIRD-PARTY-NOTICES.md), with an abort-aware Semaphore.acquire, Semaphore.tryAcquire, Semaphore.runExclusive, and a Semaphore.release that throws instead of silently ignoring a release with nothing acquired.

Class Description
Semaphore A counting semaphore for async functions. Each Semaphore.acquire takes a permit, or waits until one is released. Each Semaphore.release hands its permit to the longest-waiting acquirer, first in first out, or returns it to the pool.