Framework
AsyncMutex
Class: AsyncMutex
Simple async mutex for serializing operations.
Provides mutual exclusion in single-process environments. Does NOT provide distributed locking across processes.
Constructors
new AsyncMutex()
new AsyncMutex(): AsyncMutexReturns
Methods
acquire()
acquire(): Promise<void>Acquire the lock. Waits if the lock is already held.
Returns
Promise<void>
isLocked()
isLocked(): booleanCheck if the lock is currently held.
Returns
boolean
release()
release(): voidRelease the lock. Wakes up the next waiter if any.
Returns
void
withLock()
withLock<T>(fn): Promise<T>Execute a function while holding the lock. Ensures lock is released even if function throws.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | () => Promise<T> | Function to execute |
Returns
Promise<T>
Result of the function
