Type Alias ILockAdapter

ILockAdapter: {
    acquire(
        context: IReadableContext,
        key: string,
        lockId: string,
        ttl: null | TimeSpan,
    ): Promise<boolean>;
    forceRelease(context: IReadableContext, key: string): Promise<boolean>;
    getState(
        context: IReadableContext,
        key: string,
    ): Promise<null | ILockAdapterState>;
    refresh(
        context: IReadableContext,
        key: string,
        lockId: string,
        ttl: TimeSpan,
    ): Promise<boolean>;
    release(
        context: IReadableContext,
        key: string,
        lockId: string,
    ): Promise<boolean>;
}

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

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

Type declaration

  • acquire:function
    • Attempts to acquire a lock for the specified key. Succeeds only if the lock is currently expired or doesn't exist.

      Parameters

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        Unique identifier for the 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 lock was successfully acquired, false if already held by another owner

  • forceRelease:function
    • Forcibly releases a 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 lock

      Returns Promise<boolean>

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

  • getState:function
  • refresh:function
    • Refreshes (extends) the time-to-live of an existing 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 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 lock is unexpirable, expired, or not owned by lockId

  • release:function
    • Releases a 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 lock

      • lockId: string

        Unique identifier of the lock owner

      Returns Promise<boolean>

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