LogoRobo.js
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(): AsyncMutex

Returns

AsyncMutex

Methods

acquire()

acquire(): Promise<void>

Acquire the lock. Waits if the lock is already held.

Returns

Promise<void>


isLocked()

isLocked(): boolean

Check if the lock is currently held.

Returns

boolean


release()

release(): void

Release 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

ParameterTypeDescription
fn() => Promise<T>Function to execute

Returns

Promise<T>

Result of the function

On this page