Skip to content

Mutex

Defined in: packages/async/src/synchro/mutex.ts:16

A mutex (mutual exclusion) primitive for asynchronous tasks.

A mutex allows only one task to hold the lock at a time. Other tasks attempting to acquire the lock will wait until it is released.

The order of lock acquisition is guaranteed to be FIFO (first-in-first-out).

Note: Only meaningful when the critical section contains at least one await — synchronous operations cannot be interleaved in JS’s single-threaded model.

new Mutex(): Mutex

Mutex

get locked(): boolean

Defined in: packages/async/src/synchro/mutex.ts:19

Indicates whether the lock is currently held.

boolean

Indicates whether the lock is currently held.

ILock.locked

lock(signal?): Promise<void>

Defined in: packages/async/src/synchro/mutex.ts:27

Acquires the lock, waiting if necessary until it is available.

AbortSignal | null

An optional AbortSignal to cancel the acquire operation.

Promise<void>

A promise that resolves when the lock is acquired.

ILock.lock


tryLock(): boolean

Defined in: packages/async/src/synchro/mutex.ts:23

Attempts to acquire the lock without waiting.

boolean

True if the lock was successfully acquired, false otherwise.

ILock.tryLock


unlock(): void

Defined in: packages/async/src/synchro/mutex.ts:31

Releases the lock.

void

ILock.unlock