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.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Mutex():
Mutex
Returns
Section titled “Returns”Mutex
Accessors
Section titled “Accessors”locked
Section titled “locked”Get Signature
Section titled “Get Signature”get locked():
boolean
Defined in: packages/async/src/synchro/mutex.ts:19
Indicates whether the lock is currently held.
Returns
Section titled “Returns”boolean
Indicates whether the lock is currently held.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”lock()
Section titled “lock()”lock(
signal?):Promise<void>
Defined in: packages/async/src/synchro/mutex.ts:27
Acquires the lock, waiting if necessary until it is available.
Parameters
Section titled “Parameters”signal?
Section titled “signal?”AbortSignal | null
An optional AbortSignal to cancel the acquire operation.
Returns
Section titled “Returns”Promise<void>
A promise that resolves when the lock is acquired.
Implementation of
Section titled “Implementation of”tryLock()
Section titled “tryLock()”tryLock():
boolean
Defined in: packages/async/src/synchro/mutex.ts:23
Attempts to acquire the lock without waiting.
Returns
Section titled “Returns”boolean
True if the lock was successfully acquired, false otherwise.
Implementation of
Section titled “Implementation of”unlock()
Section titled “unlock()”unlock():
void
Defined in: packages/async/src/synchro/mutex.ts:31
Releases the lock.
Returns
Section titled “Returns”void