Skip to content

Interface: Semaphore

Defined in: primitives/semaphore.ts:9

An interface for a semaphore, a synchronization primitive for controlling access to a limited number of resources.

Properties

acquire()

acquire: () => Promise<ReleaseFn>

Defined in: primitives/semaphore.ts:16

Acquires a permit from the semaphore. If no permits are available, this promise-based method will block until a permit is released.

Returns

Promise<ReleaseFn>

A promise that resolves with a function to call to release the permit.


tryAcquire()

tryAcquire: () => null | ReleaseFn

Defined in: primitives/semaphore.ts:23

Attempts to acquire a permit from the semaphore without blocking.

Returns

null | ReleaseFn

A function to call to release the permit if one was acquired, otherwise null.


release()

release: () => void

Defined in: primitives/semaphore.ts:29

Releases a permit back to the semaphore. This unblocks the next waiting acquire call in the queue or increments the available permit count.

Returns

void

Released under the MIT License.