ISharedLockAdapter: {
    acquireReader(settings: SharedLockAcquireSettings): Promise<boolean>;
    acquireWriter(
        context: IReadableContext,
        key: string,
        lockId: string,
        ttl: null | TimeSpan,
    ): Promise<boolean>;
    forceRelease(context: IReadableContext, key: string): Promise<boolean>;
    forceReleaseAllReaders(
        context: IReadableContext,
        key: string,
    ): Promise<boolean>;
    forceReleaseWriter(
        context: IReadableContext,
        key: string,
    ): Promise<boolean>;
    getState(
        context: IReadableContext,
        key: string,
    ): Promise<null | ISharedLockAdapterState>;
    refreshReader(
        context: IReadableContext,
        key: string,
        slotId: string,
        ttl: TimeSpan,
    ): Promise<boolean>;
    refreshWriter(
        context: IReadableContext,
        key: string,
        lockId: string,
        ttl: TimeSpan,
    ): Promise<boolean>;
    releaseReader(
        context: IReadableContext,
        key: string,
        slotId: string,
    ): Promise<boolean>;
    releaseWriter(
        context: IReadableContext,
        key: string,
        lockId: string,
    ): Promise<boolean>;
}

Technology-agnostic adapter contract for managing distributed shared locks (reader-writer locks). Implementations handle writer lock and reader semaphore acquisition, release, refresh, and state tracking independent of the underlying storage. Note: This contract is low-level and typically not used directly - prefer ISharedLockFactory for shared lock usage.

IMPORT_PATH: "@daiso-tech/core/shared-lock/contracts"

Type declaration

  • acquireReader:function
    • Attempts to acquire a reader slot in the shared lock. Succeeds only if no non-expired writer lock is held and the current number of acquired reader slots has not reached the limit.

      Parameters

      Returns Promise<boolean>

      Promise resolving to true if the reader slot was successfully acquired, false if the slot limit has been reached

  • acquireWriter:function
    • 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

      • context: IReadableContext

        Readable execution context for the operation

      • 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

      Returns Promise<boolean>

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

  • forceRelease:function
    • Forcibly releases both the writer lock and all reader slots regardless of ownership. Used for complete emergency cleanup of the shared lock.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      Returns Promise<boolean>

      Promise resolving to true if the shared lock existed and was fully released, false if the shared lock doesn't exist

  • forceReleaseAllReaders:function
    • 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

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      Returns Promise<boolean>

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

  • forceReleaseWriter:function
    • 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

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      Returns Promise<boolean>

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

  • getState:function
  • refreshReader:function
    • Refreshes (extends) the time-to-live of an existing reader slot. Only succeeds if all conditions are met: the slot exists, hasn't expired, and is expirable.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      • slotId: string

        Unique identifier of the reader slot to refresh

      • ttl: TimeSpan

        New time-to-live duration to set

      Returns Promise<boolean>

      Promise resolving to true if refresh succeeded, false if the slot is unexpirable, expired, or doesn't exist

  • refreshWriter:function
    • 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

      • context: IReadableContext

        Readable execution context for the operation

      • 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

      Returns Promise<boolean>

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

  • releaseReader:function
    • Releases a specific reader slot if it is currently acquired. Only the holder of the slot (identified by slotId) can release it.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      • slotId: string

        Unique identifier of the reader slot to release

      Returns Promise<boolean>

      Promise resolving to true if the reader slot was successfully released, false if the slot doesn't exist or is already released

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

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the shared lock

      • lockId: string

        Unique identifier of the lock owner

      Returns Promise<boolean>

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