Body, Mind & Soul — API Reference
    Preparing search index...

    Minimal async mutex for serializing concurrent promise-based operations.

    Maintains an internal promise chain that ensures each function passed to .acquire() runs after the previous one completes, preventing race conditions when multiple coroutines compete for write access to a shared resource.

    Errors in one function do not break the chain — the queue continues processing.

    const mutex = new AsyncMutex();
    await mutex.acquire(async () => {
    // This block runs serially relative to all other acquire() calls
    });
    Index
    • Acquire the mutex and run the given function serially relative to all other pending operations.

      Parameters

      • fn: Function

        Async function to run once this mutex's chain reaches its turn

      Returns Promise<any>

      • Resolves when fn completes