Note the MemorySharedLockAdapter is limited to single process usage and cannot be shared across multiple servers or different processes. This adapter is meant for easily fakingISharedLockFactory for testing.

IMPORT_PATH: "@daiso-tech/core/shared-lock/memory-shared-lock-adapter"

Implements

Constructors

Methods

  • Attempts to acquire a writer lock for the specified key. Succeeds only if no non-expired writer lock exists and no non-expired reader slots are held.

    Parameters

    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier for this acquirer (becomes the owner)

    • ttl: null | TimeSpan

      Time-to-live duration or null for indefinite locks

    • _context: IReadableContext

    Returns Promise<boolean>

    Promise resolving to true if the writer lock was successfully acquired, false if already held by another owner

  • Forcibly releases all reader slots for the specified shared lock regardless of ownership. Used for emergency cleanup or administrative operations. Bypasses ownership verification for situations where individual slot holders are unavailable.

    Parameters

    • key: string

      Unique identifier for the shared lock

    • context: IReadableContext

      Readable execution context for the operation

    Returns Promise<boolean>

    Promise resolving to true if reader slots existed and were released, false if no reader slots are acquired

  • Forcibly releases a writer lock regardless of ownership. Used for emergency lock release or administrative cleanup. Bypasses ownership verification for situations where the owner is unavailable.

    Parameters

    • key: string

      Unique identifier for the shared lock

    • context: IReadableContext

      Readable execution context for the operation

    Returns Promise<boolean>

    Promise resolving to true if the writer lock existed and was released, false if the lock is already expired

  • Refreshes (extends) the time-to-live of an existing writer lock. Only succeeds if all conditions are met: ownership matches, lock hasn't expired, and it's expirable.

    Parameters

    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier of the lock owner

    • ttl: TimeSpan

      New time-to-live duration to set

    • _context: IReadableContext

    Returns Promise<boolean>

    Promise resolving to true if refresh succeeded, false if the lock is unexpirable, expired, or not owned by lockId

  • Releases a writer lock if owned by the specified lockId. Ownership verification prevents accidental release of locks held by others.

    Parameters

    • key: string

      Unique identifier for the shared lock

    • lockId: string

      Unique identifier of the lock owner

    • _context: IReadableContext

    Returns Promise<boolean>

    Promise resolving to true if the writer lock was successfully released, false if not owned by lockId or doesn't exist