@ac-essentials/misc-util
    Preparing search index...

    Class RwLock

    An asynchronous read-write lock (RwLock) for coordinating access to shared resources.

    Allows multiple concurrent readers or exclusive access for a single writer.

    All lock/unlock operations are asynchronous and must be awaited.

    WARNING: Deadlock is possible if:

    • A task attempts to acquire a lock it already holds (no reentrancy).
    • Locks are acquired in inconsistent order across tasks.
    • A task forgets to unlock after acquiring.

    Best practices:

    • Always use try/finally to ensure unlock.
    • Avoid holding locks across await points that may block indefinitely.
    • Never call lock methods from within unlock callbacks.

    Example usage: await rwLock.readLock(); try { // read shared resource } finally { rwLock.readUnlock(); }

    Index

    Constructors

    Methods

    • Acquire a read lock. Multiple readers may hold the lock concurrently unless a writer is waiting or active.

      Parameters

      • Optionalsignal: AbortSignal | null

        Optional AbortSignal to cancel the wait.

      Returns Promise<void>

      Error if the lock cannot be acquired due to cancellation.

    • Upgrade a held read lock to a write lock. The caller must already hold a read lock.

      Parameters

      • Optionalsignal: AbortSignal | null

        Optional AbortSignal to cancel the wait.

      Returns Promise<void>

      Error if the upgrade cannot be completed due to cancellation.

    • Acquire a write lock. Only one writer may hold the lock, and no readers may be active.

      Parameters

      • Optionalsignal: AbortSignal | null

        Optional AbortSignal to cancel the wait.

      Returns Promise<void>

      Error if the lock cannot be acquired due to cancellation.